开发者

Verify that I am connected to my MongoDB via Mongoose?

开发者 https://www.devze.com 2023-03-19 08:11 出处:网络
I am trying to learn Node.js and using MongoDB. I got an insert working correctly and can insert as many objects as I want, however I cannot seem to query them at all.

I am trying to learn Node.js and using MongoDB.

I got an insert working correctly and can insert as many objects as I want, however I cannot seem to query them at all.

I have tried using every technique posted here and none of them return any of my objects.

I have verified via the Mongo console that the objects exist but I just can't query them and I am absolutely lost as to why.

Here is the current code I'm using to query:

User.findOne({ 'user.name': 'James' }, function(user){
    console.log("Got " + user);
    res.send(us开发者_运维百科er);
  });

Help?

EDIT

The above code returns "null".


Nearly every time I post a question on SO lately I seem to find the answer myself within 15 minutes.
The answer to this one, is that my callback function is only accepting 1 argument of "user". The first argument in the callback is any Errors that are raised, so obviously there are no errors raised.

Changing the callback to this fixes it:

function(err, user) {
}
0

精彩评论

暂无评论...
验证码 换一张
取 消