所以,我几个小时以来一直在尝试,但没有得到任何结果。
我有一个 MongoDB 集合,它有一个日期值"scrape_systemTime"
,我将其插入scrape_systemTime : new Date()
.
我试图通过使用以下方法获得早一周的结果:
db.scrape.find({scrape_systemTime: { $lt: new Date( Date.now() - 86400000*7)}})
它应该返回一组看起来像下面的对象的文档,但它什么也不返回。 (看着那(这"scrape_systemTime"
属性,其日期早于一周。)
[{
"newspaperID" : "6",
"scrape_systemTime" : "Fri Oct 25 2013 13:14:10 GMT+0000 (UTC)",
"_id" : ObjectId("526a6ea1985ba76408000010"),
"languageID" : "1",
"scrape_tabs_title" : "India",
"scrape_tabs_href" : "http://www.indianexpress.com/supplement/India/798/",
"scrape_thumb" : "images/default/noimage.jpg",
"scrape_href" : "http://www.indianexpress.com/news/political-parties-woo-chhattisgarh-youth-on-facebook-whatsapp/1187180/",
"scrape_title" : "Political parties woo Chhattisgarh youth on Facebook, WhatsApp",
"scrape_largeimage" : "http://static.indianexpress.com/m-images/Fri Oct 25 2013, 17:57 hrs/M_Id_433064_facebook.jpg",
"scrape_detail_article_text" : "",
"scrape_newstime" : "PTI : Raipur, Fri Oct 25 2013, 18:11 hrs",
"scrape_status" : "Pending",
"viewCount" : 0,
"error_log" : "OK",
"ip" : "192.168.0.101"
}, ...]
但如果我使用_id
对于日期条件,即创建ObjectId()
具有一周前的时间戳并在查询中使用,如下所示:
db.scrape.find({_id: { $lt: ObjectId( Math.floor( new Date( Date.now() - 86400000*7 ) / 1000 ).toString(16) + '0000000000000000')}})
它返回预期结果。
为什么会发生这种情况?第一个查询语法有问题吗?
图片在这里 https://i.stack.imgur.com/euW3w.png
Thanks.