2016-08-03 40 views

回答

1

您可以使用update命令与UPSERT选项:

db.yourCollection.update({id:xxx}, {id:xxx, field1:yyy, field2:zzz}, {upsert:true}) 

第一个参数是搜索查询,并应在唯一索引字段完成。第二个是要插入/更新的实际文档,第三个是要插入/更新的文档。

0

db.yourCollection.update({ID:XXX},{ID:XXX,FIELD1:YYY,FIELD2:ZZZ},{ UPSERT:假})

upsert is a Optional. If set to true, creates a new document when no document matches the query criteria. If set to false, which does not insert a new document when no match is found.