node.js mongojs findOne callback returning error as null

a 夏天 提交于 2019-11-29 10:56:38

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.

Update

Note that findOne has been deprecated in the 2.0 driver, but its replacement also exhibits this same behavior:

users.find({'fb_id' : fbUserMetadata.id}).limit(1).next(err, doc) {
    // doc is null if a matching document wasn't found
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!