2011-04-10 57 views
0

在我的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)。

+0

尝试'mongoose.model('东西')' – Raynos 2011-04-10 15:16:37

回答

1

的问题是在我应该使用回调函数(ERR,东西)作为参数,而不是唯一的(东西)。

0

尝试:

Thing.findById(id, function(thing){ 
+0

我已经试过,但没有任何返回。 – Luc 2011-04-10 14:31:12