{
"name" : "XYZ",
"phone" : 12345,
"emp_id" : 9999,
"sal" : 5000
}
我想在此记录上添加数据并将其存储到另一个数据库中。我已经试过了:
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
如何以字典形式或JSON形式添加数据?
由于i
在您的示例中似乎是字典,因此您很可能需要类似i.update({'dept': 'Marketing'})
或的东西i['dept']='Marketing'
,以便引入新的键/值对
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句