pymongo - mongodb中基於位置的陣列修改
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | <code>**>db.blog.findOne()
{ "_id" : "djsofjwo"
"comments" :[
{
"comment" : "good post" ,
"author" : "john"
"vote" :0}
{
"comment" : "I thought it is too short"
"author" : "bob"
"vote" :3
}
{
"comment" : "good"
"author" : "light"
"vote" :1
}
]
}
>db.blog.update({ "post" :post_id},{ "$inc" :{ "comments.0.vote" :1}})
</code>
|
這樣是在shell 的環境下對comments數組中位置為0的評論修改,使投票加一。在pymongo下怎麼用python程式碼實現同樣的功能? **