【发布时间】:2015-02-26 00:57:13
【问题描述】:
这是我的代码,我得到了文档的空值。但是在 findOne({'webpageid':docs[i]._id} 而不是 docs[i]._id 中,如果我传递了 pagesid 它可以工作。并且我验证了 docs 具有所需的网页数据
// get all the records from the webpages table
var collection = db.get('webpages');
collection.find({}, function(e,docs){
// iterate over the webpage list
for (var i = 0; i < docs.length; i++) {
// check if results table has any record for this webpage
db.get('results').findOne({'webpageid':docs[i]._id}, function(err, doc)
{
if(err)
{
return;
}
console.log(doc);
});
};
});
以下是“网页”表中的内容
{
"_id" : ObjectId("549608e16ecb16dc3c4880e6"),
"name" : null,
"url" : "http://www.google.com",
"texttoverify" : null,
"interval" : null,
"websiteid" : null
}
{
"_id" : ObjectId("549609986ecb16dc3c4880e7"),
"name" : null,
"url" : "http://www.google.com",
"texttoverify" : null,
"interval" : null,
"websiteid" : null
}
{
"_id" : ObjectId("54960a916ecb16dc3c4880e8"),
"name" : "xyz",
"url" : "http://www.google.com",
"texttoverify" : "hello",
"interval" : "00:15:00.0000000",
"websiteid" : "02D7BE81-4E01-4347-BAE5-BA9A2D7EE11E"
}
这是我在“结果”表中的内容
{
"_id" : ObjectId("54985a1e69af082f9c477574"),
"webpageid" : "549608e16ecb16dc3c4880e6"
}
{ "_id" : ObjectId("54986f4e69af082f9c477575"), "name" : "name" }
{
"_id" : ObjectId("5498d10c69af082f9c477576"),
"name" : "name",
"webpageid" : "\"54960a916ecb16dc3c4880e8"
}
{
"_id" : ObjectId("5498d1f969af082f9c477577"),
"name" : "name",
"webpageid" : "54960a916ecb16dc3c4880e8"
}
感谢您的调查并感谢您的帮助。
【问题讨论】:
-
您需要提取ObjectId的HexaDecimal String值,然后使用它来查询结果集合。 - stackoverflow.com/questions/13104690/…,因为
results集合有webpageid作为字符串,而不是ObjectId。
标签: javascript node.js mongodb