简体   繁体   中英

How to update a array value inside a dict value

在此处输入图像描述

I have a dict with key and value. In value i have a dict with key and a array value again. I want to know how to append datas inside that array value with pymongo?!

i = mycol2.find_one({"chat_action":{"$exists":True}})
mycol2.update_one(i,{"$push":{"chat_action":{"fake_play":76}}})

I try this but i got this error:

raise WriteError(error.get("errmsg"), error.get("code"), error) pymongo.errors.WriteError: The field 'chat_action' must be an array but is of type object in document {_id: ObjectId('62eaafa3886a0c39b0961b0a')}, full error: {'index': 0, 'code': 2, 'errmsg': "The field 'chat_action' must be an array but is of type object in document {_id: ObjectId('62eaafa3886a0c39b0961b0a')}"}

You need to fully qualify the field with dot notation:

    {"$push": {"chat_action.fake_play": 76 } }

From the docs ,

To specify a field in an embedded document or in an array, use dot notation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM