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)。