简体   繁体   English

为什么我的回叫功能无法运行?

[英]Why does my call back function not run?

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");
    });

The problem with this code is the callback function does not seem to run. 此代码的问题是回调函数似乎未运行。 THIS IS A TEST does not get outputted. 不会输出此测试。

I am connected to a database, db is passed into this function as an argument. 我已连接到数据库,db作为参数传递给此函数。 What are the possible problems? 可能有什么问题?

findOne() doesn't receive a callback as second parameter, the second one is a projection which means that if you define it will only return the specified parameters db.collection.findOne(query, projection) . findOne()不会收到作为第二个参数的回调,第二个是一个projection ,这意味着如果您定义它,将仅返回指定的参数db.collection.findOne(query, projection) That's way your callback is not been executed. 这样就不会执行您的回调。 findOne documentation here 在这里找到一个文档

Examples here 这里的例子

Updated: 更新:

According to the comments seems to be this docs (my mistake) , but the issue was the missing second parameter findOne(query, options, callback) 根据评论似乎是这个文档 (我的错误) ,但是问题是缺少第二个参数findOne(query, options, callback)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM