[英]Retrieve data from a collection(mongo),modify the returned object and insert it into another mongo collection
{
"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? 如何以字典形式或JSON形式添加数据?
由于在您的示例中i
似乎是字典,因此您很可能需要类似i.update({'dept': 'Marketing'})
或i['dept']='Marketing'
,以引入新的键/值对
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.