MongoDB CRUD Operations - Yash-777/mongo-java-driver GitHub Wiki
db.collection_name.
CURD Operations over Collection Data Refereed examples
db.student.insert({
regNo: "3014",
name: "Test Student",
course: {
courseName: "MCA",
duration: "3 Years"
},
address: {
city: "Bangalore",
state: "KA",
country: "India"
}
})
For Example : Let us retrieve the record from the student collection where the attribute regNo is 3014 and the query for the same is as shown below:
db.students.find({"regNo":"3014"})
Let us update the attribute name of the collection student for the document with regNo 3014.
db.student.update({
"regNo": "3014"
},
$set:
{
"name":"Viraj"
})
Removing an entry from the collection (Delete) « Let us now look into the deleting an entry from a collection. In order to delete an entry from a collection, run the command as shown below :
db.student.remove({"regNo":"3014"})
Note that after running the remove() method, the entry has been deleted from the student collection.