0

node.js / expressアプリで、mongoDBを調べると、次のようになりました。

 > db.things.find()[0]._id                                
 ObjectId("4da06702584ca3f402000001")

ID4da06702584ca3f402000001のコレクションが存在します。しかし、リクエストを使用すると、元に戻すことができません。

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関数ではなく、使用するコールバックメソッドにあります...提供する必要がある単一のパラメーター(thing)を1つだけ提供しました(err、tring)。

4

2 に答える 2

1

問題は、(thing)だけでなく、(err、thing)をパラメーターとして使用する必要があるコールバック関数にありました。

于 2011-04-10T19:44:34.893 に答える
0

試す:

Thing.findById(id, function(thing){
于 2011-04-10T14:21:26.547 に答える