CRUD

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

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

Figure 823. Multi valued attributes Slide presentation

Figure 824. Set semantics of multivalued attributes Slide presentation

Figure 825. Deleting selected attribute values Slide presentation

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