使用idObject按日期过滤

时间:2016-02-01 02:30:41

标签: c# mongodb date driver mongodb-.net-driver

Hí,这个mongoDB查询,使用idObject字段按日期过滤文档。

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")}})

如何使用C#驱动程序实现此功能?已经有任何方法可以将日期转换为idObject?

参考文章:http://www.sitepoint.com/beginning-android-install-an-android-platform/

1 个答案:

答案 0 :(得分:3)

该驱动程序的开发人员之一告诉我一个非常有趣的构造函数。我希望这对未来的人有用:

// 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)));