Pymongo 如何正确使用 $push 更新现有文档 [英] Pymongo how to properly use $push to update an existing document
本文介绍了Pymongo 如何正确使用 $push 更新现有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我做错了什么或者我不明白 $push (可能不明白).无论如何,我有以下文件:
I am doing something wrong or I don't understand $push (probably don't understand). Anyway I have the following document:
{
"_id" : ObjectId("501c83051d41c8753e000000"),
"node" : "denver",
"enc" : {
"environment" : "production",
"classes" : {
"denver" : ""
}
},
"inherit" : "default"
}
我正在尝试制作文档
{
"_id" : ObjectId("501c83051d41c8753e000000"),
"node" : "denver",
"enc" : {
"environment" : "production",
"classes" : {
"denver" : "",
"boulder" : ""
}
},
"inherit" : "default"
}
这是我的更新语句的样子:
This is what my update statement looks like:
col.update(
{
'node' : 'denver'
},
{
'$push': {
'enc.classes' : {
'boulder': ''
}
}
},
True)
我没有收到错误,但文档永远不会更新.如果我将 $push 更改为 $set,那么 denver 将被替换为 boulder.
I don't get an error but the document never updates. If I change $push to $set then the denver is replaced with boulder.
感谢您的任何帮助.
推荐答案
此查询有效.
db.foo.update({"node": "denver"}, {"$set": {"enc.classes.boulder": ""}}
这篇关于Pymongo 如何正确使用 $push 更新现有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文