1
所以,我一直试着这样做,但没有得到任何结果。日期查询适用于_id,但不适用于Date值 - MongoDB
我有一个日期值为"scrape_systemTime"
的MongoDB集合,我将它与scrape_systemTime : new Date()
一起插入。
我试图用得到的结果年长1周是:
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')}})
它返回预期结果。
这是怎么发生的?在第一个查询语法中有什么不对吗?
谢谢。
是的,这是问题。 –