How to realize that if the data exists, update if it does not exist, delete it in mongo
MongoDb278
description
Update the data whose name is cmdhelp in the test table, if it does not exist, create it
command
db.test.update( { "name": "cmdhelp" }, { "$set": { "age":1} }, { upsert: true } )
parameter
update : modify an existing document or a document in a collection $set : Append new fields to existing documents upsert : If no document matches the query, create a new document
result
Updated 1 new record(s) in 17ms