Quick question: In mongo ( or any db for that matter), are upsert queries a better alternative to insert + update query.
upsert
-> finds and updates document if found else inserts a new document. I've read articles saying this makes life easier and is performance effective. (Essentially two operations)
insert
-> checks if document exists, if not -> insert document else throw an error. ( 2 operations)
update
would be the reverse of insert. (2 operations again )
From this upsert
seems to be a better choice but what if I had data which rarely gets updated. Would having an insert
& update
query make more sense or an upsert
operation?