mongoDB--update和delete

The update and delete methods provided by mongoDB include operations on a document in the collection (similar to limit 1), as well as operations on multiple doucuments in the collection, and also support blukUpdate (this is a bit like the blukUpdate provided by hibernateTemplate or jdbcTemplate)

UPDATE OPERATION:

  1.updateOne

  db.class.updateOne({

      filterProp:{$lt:filterVal}

    },{

      $set : {setProp:setVal}    

   })

equal

update class set setProp=setVal

where filterProp < filterVal

limit 1

Just modify the update information of a hit data

 Well, I was wrong, my version does not support updateOne, only update

  2.updateMany

   db.class.updateMany({

      filterProp:{$lt:filterVal}

    },{

      $set : {setProp:setVal}    

   })

equal

update class set setProp=setVal

where filterProp < filterVal

  3.replaceOne (I am experimenting with a lower version of mongoDB)

replaceOne is actually the same as the update in my texture, and the difference from updateOne is:

  updateOne is to replace the value of a prop in the document

  replaceOne is to replace the satisfied document with the following collection



 

DELETE OPERATION:

 1.deleteOne

Below is an excerpt from API

 The following diagram highlights the components of the MongoDB deleteOne() operation:

The components of a MongoDB deleteOne operation.

The following diagram shows the same query in SQL:

The components of a SQL DELETE statement with LIMIT 1.

 2.deleteMany

 


The following diagram highlights the components of the MongoDB deleteMany() operation:

The components of a MongoDB deleteMany operation.

The following diagram shows the same query in SQL:

The components of a SQL DELETE statement.

 3.remove



 

The difference between remove and deleteOne:

No difference has been found so far. . . . //TODO to be added

 

bulkWrite: (new function in version 3.2)

It is to combine the corresponding update behavior into a jsonArray to take effect at one time.

db.collection.bulkWrite(
   [
      { insertOne : { "document" : { name : "sue", age : 26 } } },
      { insertOne : { "document" : { name : "joe", age : 24 } } },
      { insertOne : { "document" : { name : "ann", age : 25 } } },
      { insertOne : { "document" : { name : "bob", age : 27 } } },
      { updateMany: {
         "filter" : { age : { $gt : 25} },
         "update" : { $set : { "status" : "enrolled" } }
         }
      },
      { deleteMany : { "filter" : { "status" : { $exists : true } } } }
   ]
)

 

 

   

 

 

 

 

 


 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326905479&siteId=291194637