Mongodb update. setOnInsert Mod on _id not allowed -


i understand fact can't update _id on existing mongodb document.

but there reason can't use in upsert in 'setoninsert' part ? because 'on insert' it's not update.

my expected usage this:

db.mycol.update({_id:12345},{$setoninsert:{_id:12345},$set:{myvalue:'hi'}}); 

is bug or missing ?

mongodb uses 'query' part upsert query part of set, meaning don't have specify _id in set part of want specify own _id.

note: query above had small bug missing upsert flag.

this correct query:

db.mycol.update({_id:12345},{$set:{myvalue:'hi'}},{upsert:true}); 

if record doesn't exist, query insert record looks this:

{_id:12345,myvalue:'hi'} 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -