使用猫鼬检索模型

Retrieving model using mongoose

我想通过 "id" 从我的数据库搜索中检索整个模型。 在这种情况下最好使用哪个查询?

我的模式是这样的:

{ _id: 54b5ed4b967a4e3b96fe8a39,
  email: 'blabla@yahoo.com',
  __v: 0,
  deleted: false,
  createdAt: Tue Jan 13 2015 23:15:07 GMT-0500 (EST),
  shipping: {},
  profile: { picture: '', location: 'Romania', name: 'bla' },
  tokens: [],
  role: 'shopper'} 

而我拥有的是:54b5ed4b967a4e3b96fe8a39

如果您知道要查找的 Model 的类型,即 Person。只要做:

var id = "54b5ed4b967a4e3b96fe8a39";
Person.findById(id, function(err, person) {
    if (err) {
        return console.log('oh no! error', err);
    }
    console.log('found person', person);
});

文档here