Filter by date using an idObject

不问归期 提交于 2020-02-08 05:28:30

问题


Hí, this mongoDB query, filter documents by date using an idObject field.

db.myCollection.find({_id:{$gt: ObjectId(Math.floor((new Date('1990/10/10'))/1000).toString(16) + "000
0000000000000"), $lt: ObjectId(Math.floor((new Date('2011/10/10'))/1000).toString(16) + "000
0000000000000")}})

How would you implement this using the C# driver? There's already any method to convert a date to idObject?

Reference post: https://stackoverflow.com/a/13594408/2010764


回答1:


One of the developers of the driver, told me about a very interesting constructor. I hope this will be useful to someone in the future:

// Get all documents created today.
var query = Query.And(
    Query.GTE("_id", new ObjectId (DateTime.UtcNow.Date,0,0,0)),
    Query.LT ("_id", new ObjectId (DateTime.UtcNow.Date.AddDays(1),0,0,0)));


来源:https://stackoverflow.com/questions/35122191/filter-by-date-using-an-idobject

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!