public class ScheduledEvent : Event
{
public DateTimeOffset StartDateTime { get; set; }
}
StartDateTime = 5/27/2013 2:09:00 AM +00:00 代表 05/26/2013 07:09 PM PST
MongoDB中记录的内容:
> db.ScheduledEvent.find().toArray()
[
{
"_id" : BinData(3,"ZE2p31dh00qb6kglsgHgAA=="),
"Title" : "Today 26th at 7:09pm",
"Length" : "00:00:00",
"MoreInformation" : "http://1.com",
"Speakers" : [
{
"_id" : BinData(3,"ndzESsQGukmYGmMgKK0EqQ=="),
"Name" : "Mathias Brandewinder"
}
],
"Location" : {
"_id" : BinData(3,"AAAAAAAAAAAAAAAAAAAAAA=="),
"Name" : "Somwhere "
},
"Organizers" : [
{
"_id" : BinData(3,"AAAAAAAAAAAAAAAAAAAAAA=="),
"Name" : null
}
],
"CreatedOn" : [
NumberLong("635052144104050898"),
0
],
"StartDateTime" : [
NumberLong("635052173400000000"),
0
]
}
]
我意识到 StartDateTime 在 MongoDB 中存储为 Ticks。
var dateMarker = DateTimeOffset.UtcNow;
var nextDay = dateMarker.AddDays(1);
此查询不起作用:
var today = EventRepoistory.All().Where(z => z.StartDateTime >= dateMarker && z.StartDateTime < nextDay).OrderByDescending(z => z.StartDateTime).ToList();
我已经向 Mongo C# 驱动程序添加了一个查询显示,它显示了以下查询:
{ "$query" : { "StartDateTime" : { "$gte" : [NumberLong("635052168609734070"), 0], "$lt" : [NumberLong("635053032609734070"), 0] } }, "$orderby" : { "StartDateTime" : -1 } }
下限 = 6350521 68609734070
服务器 = 6350521 73400000000
上限 = 6350530 32609734070
问题:为什么 MongoDB 查询不返回任何内容?
db.ScheduledEvent.find({ "$query" : { "StartDateTime" : { "$gte" : [NumberLong("635052168609734070"), 0], "$lt" : [NumberLong("635053032609734070"), 0] } }, "$orderby" : { "StartDateTime" : -1 } })
研究:
MongoDB 和 DateTimeOffset 类型,但它表明 LINQ 提供程序正在做它应该做的事情?
试过:
db.ScheduledEvent.find({ "StartDateTime" : { "$gte" : [NumberLong("1"), 0] } } )
不产生任何结果。