Insert, Update in single query Mongodb (NodeJs)

We will talk about the fastest JSON based database ie MongoDb. The powerful database to handle bigdata now a days which keeps data in JSON format.

Inserting and updating collection in MongoDb using NodeJs in a single command is very easy to do.

Here db is the mongodb collection instance and query and update objects are respectively the condition and record to update/insert data in collection.

Here you notice {upsert: true} which is passed in the collection update command. This is used to create a new document when no document matches the query criteria.

1 thought on “Insert, Update in single query Mongodb (NodeJs)

Leave a Reply

Your email address will not be published. Required fields are marked *