Organizational Research By

Surprising Reserch Topic

node js mongojs findone callback returning error as null


node js mongojs findone callback returning error as null  using -'javascript,node.js,mongodb,callback,mongojs'

Presently being driven up the wall by this error.

I am running a node.js app with the mongojs wrapper for mongodb. I Started mongod on the default port, then ran

var db = require('mongojs').connect('localhost:27017/my_db');
var users = db.collection('users');    
users.findOne({'fb_id' : fbUserMetadata.id}, function(err, user) {
                console.log(err);
                console.log(user);
                debugger;

    });


however err and user are both 'null'. To my knowledge, err should be populated with some kind of data even if it doesn't find anything.

How do I get the callback function to work properly? Pardon the newbie question.
    

asked Oct 13, 2015 by vijayshukla80
0 votes
6 views



Related Hot Questions

1 Answer

0 votes

When the findOne query doesn't find at least one matching document, the second parameter of the callback (in this case user) is set to null. It's not an error, so err is also null. So what you're seeing is the expected no-match-found response.

answered Oct 13, 2015 by 20shahi

...