CRUD

Figure 786. Adding a document Slide presentation
Code Result
db.group.insert(
    {
        cname: "All users",
        gid: "users",
    }
)
db.group.find()

[
  {
    "_id": {"$oid": "5fa3035932b87a0c60a6ed1a"},
    "cname": "New users",
    "gid": "users"
  }
]

Figure 787. Updating attributes Slide presentation
Code Result
db.group.update(
 {_id: ObjectId(
    "5fa3035932b87a0c60a6ed1a")},
 { $set:

     {
       cname: "New users" ,
       gidNumber: 1000 
     }
 }
)
db.group.find()

[
  {
    "_id": {"$oid": 
     "5fa3035932b87a0c60a6ed1a"},
    cname: "New users" ,
    "gid": "users",
    "gidNumber": 1000 
  }
]

Changing existing attribute value from "All Users" to "New Users".

Adding new attribute gidNumber with value 1000.


Figure 788. Deleting a document Slide presentation
Code Result
db.group.deleteOne( {"_id": ObjectId(
   "5fa3035932b87a0c60a6ed1a")});
[
  {
    "acknowledged": true,
    "deletedCount": 1
  }
]

Figure 789. Deleting multiple documents Slide presentation
Code Result
db.group.deleteMany({});
[
  {
    "acknowledged": true,
    "deletedCount": 23
  }
]

Figure 790. Multi valued attributes Slide presentation

Figure 791. Set semantics of multivalued attributes Slide presentation

Figure 792. Deleting selected attribute values Slide presentation

Figure 793. Deleting an attribute Slide presentation
Code Result
db.group.update(
    {_id: ObjectId(
    "5fa3035932b87a0c60a6ed1a")},

    { $unset:
            {
                gidNumber: 42 
            }
    }
)
db.group.find()

[
  {
    "_id": {"$oid": 
     "5fa3035932b87a0c60a6ed1a"},
    "cname": "My users",
    "gid": "users"
  }
]

Though the attribute is to be deleted the operation requires a dummy value for syntactical reasons.