CRUD

Figure 813. 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 814. 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 815. Deleting a document Slide presentation
Code Result
db.group.deleteOne( {"_id": ObjectId(
   "5fa3035932b87a0c60a6ed1a")});
[
  {
    "acknowledged": true,
    "deletedCount": 1
  }
]

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

Figure 817. Multi valued attributes Slide presentation

Figure 818. Set semantics of multivalued attributes Slide presentation

Figure 819. Deleting selected attribute values Slide presentation

Figure 820. 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.