var user_col = db.collection('users');
var cursor = user_col.findOne({email:'testuser1@test.com', password:'test'}, function(err,doc){
console.log("THIS IS A TEST");
});
这段代码的问题是回调函数似乎没有运行。
这是一个无法输出的测试。
我连接到一个数据库,db作为参数传递给这个函数。可能的问题是什么?
最佳答案
findOne()
没有作为第二个参数接收回调,第二个参数是一个projection
这意味着如果定义它,它将只返回指定的参数db.collection.findOne(query, projection)
。这样就不会执行回调。
findOne documentation here
Examples here
更新时间:
根据评论似乎是this docs(我的错误),但问题是缺少第二个参数findOne(query, options, callback)