1
我是相当新的NodeJS
和MongoDB
查找在MongoDB的ID返回null
我试图做一个很基本的东西,但它似乎并不奏效。
我相信我在某处丢失了某些东西。
基本上,我试图从基于id的数据库中找到一个用户。
这里是我的代码:
function findUser(id, cb) {
MongoClient.connect(cs, function(err, db) {
var col = db.collection('users');
col.findOne({ _id: id }, function(err, user) {
// Value of user here is always null
// However, if I manually check the database,
// I can clearly see that the user with the
// same id does exists.
return cb(err, user);
});
});
}
非常感谢月亮!我会试一试。 – nirali35
这似乎是工作。再次感谢。 – nirali35