gpt4 book ai didi

python - 使用 MongoDB ( Python ) 将新属性插入文档

转载 作者:IT老高 更新时间:2023-10-28 11:06:14 25 4
gpt4 key购买 nike

我是 MOngoDB 的新手(来自 CouchDB),在使用 MonDB python 驱动程序向 MongDB 中的文档添加新属性时遇到问题。

例如,我有以下文档:

{
'_id':123456,
'text':"this is nice"
}

而我想插入一个新的属性,例如:

{
'_id':123456,
'text':"this is nice",
'created_time':datetime.datetime.now()
}

如何将 created_time 属性添加到我的文档中?

谢谢!

最佳答案

db.collection.update({'_id' : ObjectId(...)}, 
{'$set' : {'create_time' : datetime(..) }})

关于python - 使用 MongoDB ( Python ) 将新属性插入文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5056190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com