1.

Explain the SET Modifier in MongoDB?

Answer»

If the VALUE of a field does not yet exist, the "$set" sets the value. This can be USEFUL for updating schemas or adding user-defined keys.

Example:

> db.users.findOne(){ "_id" : OBJECTID("4b253b067525f35f94b60a31"), "name" : "alice", "age" : 23, "sex" : "female", "location" : "India"}

To add a field to this, we use “$set”:

> db.users.updateOne({"_id" : ObjectId("4b253b067525f35f94b60a31")},... {"$set" : {"FAVORITE book" : "Start with Why"}})


Discussion

No Comment Found