简体   繁体   中英

No result from MongoDB / MongoJS query

I'm trying to query my DB for users, but nothing happens when I try.

Here is my code to query the DB:

console.log("before db.user");
db.user.find({steamid: userSteamId}, function(err, user){
  if(err || !user){
    console.log("No account found, prompt for tradelink to create acct");
    //createUser(userSteamId, tradelink);
  } else user.forEach( function(tradelink){
      console.log(tradelink);
    });
});
console.log("after db.user");

Here is the console output:

before db.user
after db.user

There are no error messages, and neither the if, nor the else console.log statements are echoed to the console. What's wrong here, and is there any way I can see the responses from my query?

try to log user before iterating it. it might be empty in that case your query is wrong or there is no matching data in the database.

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