Note that there are some explanatory texts on larger screens.

plurals
  1. POFind by specific code results in null
    primarykey
    data
    text
    <p>I'm very new to Nodejs and i'm trying to find a record in my db(mongo) by submitting a code and crosschecking the record to see if it exists.</p> <p>I'm not really clear on how to approach this to get to an endresult stating "There is a code, please continue" and "There is no code".</p> <p>This is what i have so far as a result of my fiddling:</p> <p>userProvider.js:</p> <pre><code>UserProvider.prototype.findByCode = function(code, callback) { this.getCollection(function(error, user_collection) { user_collection.findOne({code: code}, function(error, result) { callback(error, result) }); }); } </code></pre> <p>The get collection belonging to userProvider.js:</p> <pre><code>UserProvider.prototype.getCollection= function(callback) { this.db.collection('users', function(error, user_collection) { if( error ) callback(error); else callback(null, user_collection); }); }; </code></pre> <p>app.js:</p> <pre><code>app.post('/game/code', function(req, res) { if (req.param('code')) { userProvider.findByCode(req.param('code'), function(error, result) { console.log(error); console.log(result); }); } }); </code></pre> <p>And the jade form submitting the code:</p> <pre><code>extends layout block content h1= "Gimme a code" div form( method="post") div div span.label code : input(type="text", name="code", id="code") div input(type="submit", value="Verbind") </code></pre> <p>Console logging the param('code') results in the code. So i'm pretty sure that one's solid. So why's there a null returned?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload