1

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(user);
  });

Help?

EDIT
The above code returns "null".

4

1 回答 1

2

几乎每次我最近在 SO 上发布问题时,我似乎都能在 15 分钟内自己找到答案。
这个问题的答案是,我的回调函数只接受“用户”的 1 个参数。回调中的第一个参数是引发的任何错误,因此显然没有引发任何错误。

将回调更改为此修复它:

function(err, user) {
}
于 2011-07-12T04:50:22.460 回答