UPSERT in MongoDB is used to create a new document while no document matches the query criteria, it is an optional parameter you can give in UPDATE query.
For Example: there is list you document containing names db.collection.find();
{ "_id" : ObjectId("5b0d1a2e44d67bdc91e63816"), "name" : "amy" }
{ "_id" : ObjectId("5b0d1a3d44d67bdc91e63817"), "name" : "jack" }
Think about a situation where you do not have document with name ben in your collection and you are still updating the value to Lee, setting up UPSERT option to true will create one document with name Lee even if it does not find document where name is ben. Below is the update query with use of UPSERT
db.collection.update({"name": "ben"}, {"name": "Lee"}, {upsert: true});
Below is the document created after use of UPSERTin update query.
{ "_id" : ObjectId("5b0d2d8a72d07236a420a333"), "name" : "Lee" }
Hope this answer will help you understand the use of UPSERT.
Happy coding!!