这可能在python中执行此短格式,我收到错误,
>> collection.insert({u'name.first': u'John'})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/someone/env/local/lib/python2.7/site-packages/pymongo/collection.py", line 415, in insert
self.uuid_subtype, client)
bson.errors.InvalidDocument: key 'name.first' must not contain '.'
编辑:感谢shx2指出我,插入应该更新。在网上冲浪后,我找到了答案,
>> collection.update({_id: <some_id_or_index>}, {$set: {<python_dict_object_to_be_updated>}}
答案 0 :(得分:2)
您尝试做的是更新现有文档的(子文档),因此您应该使用update
而不是insert
insert
用于将新文档添加到集合中。