How to realize that if the data exists, update if it does not exist, delete it in mongo


Update the data whose name is cmdhelp in the test table, if it does not exist, create it


   { "name": "cmdhelp" },
   { "$set": { "age":1} },
   { upsert: true }


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


Updated 1 new record(s) in 17ms
Was this helpful?

I hope to help every developer quickly find the commands they need. Of course, you can also add your own commonly used commands for easy searching.