2016-08-03 8 views

Antwort

1

Sie können den Update-Befehl mit der Upsert Option:

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

Der erste Parameter die Suchabfrage und soll auf ein eindeutig indiziertes Feld erfolgen. Das zweite ist das eigentliche Dokument, das eingefügt/aktualisiert werden soll, und das dritte sagt ihm, ein Upsert zu machen.

0

db.yourCollection.update ({id: xxx}, {id: xxx, feld1: yyy, field2: zzz}, { Upsert: false})

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. 
Verwandte Themen