在我的Node.js /快遞的應用程序,當我看着MongoDB中,我有以下幾點:的Node.js/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();
});
沒有返回。
有什麼想法?
* UPDATE *
這不起作用或者:
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)。
嘗試'mongoose.model('東西')' – Raynos 2011-04-10 15:16:37