Node.js mongojs findOne returns return error as null

Currently, this error occurs on the wall.

I am running a node.js application with the mongojs shell for mongodb. I started mongod on the default port and then launched

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". As far as I know, error should be populated with some data, even if it does not find anything.

How to make the callback function work correctly? Have mercy on the novice question.

+5
source share
1 answer

findOne , ( user) null. , err null. , , .

, findOne 2.0, :

users.find({'fb_id' : fbUserMetadata.id}).limit(1).next(err, doc) {
    // doc is null if a matching document wasn't found
});
+9

All Articles