简体   繁体   中英

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. 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) . 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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