MongoDB与Python时间戳解析

2024-05-06 17:34:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我刚刚注意到MongoDB Python驱动程序(或DB本身?)无法以Python允许的分辨率存储DateTime对象:

ts = datetime.datetime.now()
print(ts) # datetime.datetime(2019, 2, 3, 20, 12, 8, 179786)
db.test.insert({'ts': ts})
cursor = db.test.find()
for result in cursor:
    from_db = result
print(from_db['ts']) # datetime.datetime(2019, 2, 3, 20, 12, 8, 179000)

这是预期的行为还是错误


Tags: 对象fromtestdbdatetimemongodb驱动程序分辨率