findOne not working in mongoose/node
<p>This question is to do with the mongoose module for the NodeJS platform.</p>

<p>When I run the below, how do I get to the response from the DB?:</p>

<pre><code>router.get('/profileSettings', securePages, function(req, res, next){
    databaseUserModel.findOne({'profileID':req.session.facebookProfileId}, function(err, userFromDB) {
        if(userFromDB){
            done(null, userFromDB);
        } else {
            console.log('Result does not exist');
       }
    });

    res.render('profileSettings', {title:siteName + ': Profile Settings', user:userFromDB});
})
</code></pre>

<p>It doesn't seem to work for me as userFromDB doesn't seem to exist - both in the findOne and also in the res.render methods! (undefined to be precise)</p>

<p>My databaseUserModel looks like this:</p>

<pre><code>var databaseUser = new mongoose.Schema({
   profileID:String,
   fullname:String,
   profilePic:String,
   email:String,
   birthday:String,
   location:String,
   about:String
});

var databaseUserModel = mongoose.model('databaseUser', databaseUser);
</code></pre>

<p>The error message is:</p>

<pre><code>ReferenceError: userFromDB is not defined
at Object.handle (/Users/shayan/Repos/imo/routes/routes.js:75:84)
at next_layer (/Users/shayan/Repos/imo/node_modules/express/lib/router/route.js:103:13)
at Object.securePages [as handle] (/Users/shayan/Repos/imo/routes/routes.js:20:13)
at next_layer (/Users/shayan/Repos/imo/node_modules/express/lib/router/route.js:103:13)
at Route.dispatch (/Users/shayan/Repos/imo/node_modules/express/lib/router/route.js:107:5)
at /Users/shayan/Repos/imo/node_modules/express/lib/router/index.js:205:24
at Function.proto.process_params (/Users/shayan/Repos/imo/node_modules/express/lib/router/index.js:269:12)
at next (/Users/shayan/Repos/imo/node_modules/express/lib/router/index.js:199:19)
at next (/Users/shayan/Repos/imo/node_modules/express/lib/router/index.js:176:38)
</code></pre>

<p>I feel it maybe something very simple I may be missing but I am just getting my hands dirty on NodeJS (and actually developing as a whole). I was coding in a niche language for my company before (they have developed it) so please bear with me.</p>

<p>Any input will help guys! I am really stuck on this</p>

<p>PS: my mongoose object works as I have used it to store data.</p>