[英]Inserting DateTime into MongoDB
Is there something which I need to take into consideration when Im trying to serialize data into Mongo database which is keyed by DateTime? 我试图将数据序列化到以DateTime为键的Mongo数据库时,是否需要考虑一些事项?
My data looks like this SortedDictionary<DateTime, Data> Data
and the problem Im facing is that the DateTime key have time part equal to 00:00:00
but after insertion into Mongo it is ISODate("2003-11-24T23:00:00Z")
sometimes T22:00:00Z
. 我的数据看起来像是
SortedDictionary<DateTime, Data> Data
,我面临的问题是DateTime键的时间部分等于00:00:00
但是插入Mongo之后,它是ISODate("2003-11-24T23:00:00Z")
有时是T22:00:00Z
。 I preaty sure the problem is not with data Im inserting into DB I checked on every possible place if time part is always equal to 00:00:00
and it is. 我非常确定问题不在于将数据即时消息插入数据库中,而是在时间可能总是等于
00:00:00
,我在每个可能的地方都进行了检查。
mongo默认以UTC格式存储日期,因此您似乎处于不同的时区,因此有所不同
Are you converting from a string to a datatime in C#? 您是否正在使用C#从字符串转换为数据时间? Maybe that is causing it to be off by an hour because of daylight savings, local time, or UTC.
可能是由于夏令时,当地时间或UTC导致关闭一个小时。
The C# mongodb driver handles the format. C#mongodb驱动程序处理该格式。 You could quickly test using something like an integer to be sure it's not your format prior to insertion.
您可以使用整数等快速测试,以确保它不是您插入之前的格式。 MongoDB DateTime Format
MongoDB DateTime格式
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.