MongoDB and DateTimeOffset type

北城以北 提交于 2019-12-05 03:22:41

DateTimeOffset is not serialized as a Date at all, but (by default), as an array of [ticks, timezone offset]. As such, you cannot query it the same way you would a normal date. Instead, we'll query based on the ticks. You'll need to make sure your timezone offsets are the same, otherwise this won't work.

DateTimeOffsett compareTime = DateTimeOffsett.UtcNow.AddMinutes(-15);
var result = _collection.Find(Query.GT("CreationTimestamp.0", compareTime.Ticks)).Count();

Basically, we are going to compare the first element of the stored array with the tick count. Sorry again for the time it took to arrive at this answer.

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