CRUD

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

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

Figure 795. Multi valued attributes Slide presentation

Figure 796. Set semantics of multivalued attributes Slide presentation

Figure 797. Deleting selected attribute values Slide presentation

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