在我的 node.js / express 应用程序中,当我查看 mongoDB 时,我得到以下信息:
> db.things.find()[0]._id
ObjectId("4da06702584ca3f402000001")
它确实存在一个 ID 为 4da06702584ca3f402000001 的集合。但是当我使用请求时,我无法取回它:
app.get('/thing/show', function(req, res){
res.writeHead(200, {'content-type': 'text/plain'});
Thing = mongoose.model('Thing');
id = "4da06702584ca3f402000001";
Thing.find({ _id : id }, function(thing){
console.log("THING RETRIEVED:" + thing);
res.write(JSON.stringify(thing));
});
res.end();
});
什么都没有返回。
任何想法 ?
* 更新 *
这也不起作用:
Thing.find({ _id:ObjectId("4da06702584ca3f402000001")}, function(thing){
它引发以下错误:
Error: This is an abstract interface. Its only purpose is to mark fields as ObjectId in the schema creation.
at ObjectId (/usr/local/lib/node/.npm/mongoose/1.1.24/package/lib/mongoose/schema.js:426:9)...
* 解决方案 *
我的错....
问题不在于 find 函数,而在于我使用的回调方法......我只提供了一个我应该提供的参数(事物)(err,tring)。