CRUD

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

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

Figure 798. Multi valued attributes Slide presentation

Figure 799. Set semantics of multivalued attributes Slide presentation

Figure 800. Deleting selected attribute values Slide presentation

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