最好的方式来更新您的文件,并
set在时间
00:00:00使用日期时间模块,因为
createdDate是一个DateTime对象在Python中,这样你就可以使用
datetime实例的属性
day,
year和
month。
from datetime import datetimefrom pymongo import MongoClientclient = MongoClient()db = client.testcollection = db.collectionbulkOp = collection.initialize_ordered_bulk_op()count = 0for doc in collection.find(): year = doc['createdDate'].year month = doc['createdDate'].month day = doc['createdDate'].day new_date = datetime(year, month, day) bulkOp.find({'_id': doc['_id']}).update({'$set': {'createdDate': new_date}}) count = count + 1 if count == 125: bulkOp.execute() bulkOp = collection.initialize_ordered_bulk_op()if count % 125 != 0: bulkOp.execute()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)