"if document is in collection update it, if not insert the document" query

Is there a query like: if document is in collection update it, if not insert the document

I want to do this with multiple documents in one query like insertMany

Hi @mental_N_A

This is called an upsert:

1 Like

Is it possible to do this with multiple documents like insertMany?

Quite succinctly from the above link:

When you specify the option upsert: true:

I want to do it like Query([document1, document2, document3]). It checks if each document is in the collection, if it’s not in the collection it inserts it, if it is then it’ll update it.

Try with the following:

3 Likes