{
"name" : "XYZ",
"phone" : 12345,
"emp_id" : 9999,
"sal" : 5000
}
I want to add data on this record and store it into another database. I have tried this:
db=connection.testing
results=db.test.find({"name":"XYZ"})
for i in results:
i.append('dept':'Marketing')
db.test.insert_one(i)
(please ignore the insertion being done on the same connection)
Error: i.append('dept':'Marketing')
^
SyntaxError: invalid syntax
How to add data in the dictionary form or JSON form?
由于在您的示例中i
似乎是字典,因此您很可能需要类似i.update({'dept': 'Marketing'})
或i['dept']='Marketing'
,以引入新的键/值对
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.