Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
189 views
in Technique[技术] by (71.8m points)

javascript - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...