如何从具有时间(HH:MM:毫秒)从MongoDB集合中获取大于零的值,并使用时间(HH:MM:SS)值更新它,方法是使日期值与Python脚本中的现有值保持相同?
当前数据如下-
1) "createdDate" : ISODate("2015-10-10T00:00:00Z")
2) "createdDate" : ISODate("2015-10-11T00:00:00Z")
3) "createdDate" : ISODate("2015-10-12T00:00:00Z")
4) "createdDate" : ISODate("2015-10-13T01:04:30.515Z")
5) "createdDate" : ISODate("2015-10-14T02:05:50.516Z")
6) "createdDate" : ISODate("2015-10-15T03:06:60.517Z")
7) "createdDate" : ISODate("2015-10-16T04:07:80.518Z")
如何使用mongodbsql
只选择第4、5、6和7行,并在Python脚本中将时间戳更新为零?
更新后,数据如下所示-
^{pr2}$
更新文档和^{} 时间的最佳方法是使用datetime模块,因为} 、^{} 和{a6}。在
createdDate
是Python中的datetime object,因此可以使用datetime
实例属性^{PyMongo将
ISODate()
表示为datetime
对象。MongoDB假设日期和时间是UTC格式。对于给定的UTC时间,d
,有几种方法可以获得午夜(一天的开始):相关问题 更多 >
编程相关推荐