There are n documents in the collection in the database, there are m documents to write to the collection, each document has a unique identifier "user" , a general view of {"user": "22", "info": {...}} .

The essence of the question: How can I push m documents into the collection in one sitting, so that if a user matches, he will overwrite this document, and if not, add it to the collection?
Crawled through the documentation, did not find.

    1 answer 1

    You need to use the attribute upsert = true

     db.collection.update(query, update, {upsert: true})