-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate-function.js
More file actions
15 lines (8 loc) · 877 Bytes
/
update-function.js
File metadata and controls
15 lines (8 loc) · 877 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// update method in mongoDb
db.Students.updateOne(filter , update) // syntax of updation of the data in database
db.Students.updateOne({name:"abhi"},{$set:{fulltime:true}}) // this command updates the data in the database where the name is "abhi" and sets the full
// $set parameter is used to set new value in the dataset
db.Students.updateOne({name:"abhi"},{$unset:{fulltime:""}}) // unsets the fulltime field in the dataset where the name is "abhi"
db.Students.updateMany({},{$set:{fulltime:false}}) // updates the value and sets the fulltime field to false in all the datasets in the database
db.Students.updateMany({fulltime:{$exists:true}},{$set:{fulltime:""}})
// this command first checks if the value "fulltime" exist in the data using $exists command and then updates the value and sets the fulltime field to empty string in all the datasets in the database.