Performing CRUD operations in MongoDB

Hi viewers

This article will give you some basic CRUD operation of MongoDB. Using terminal you can perform these CRUD operations. Try it out in your mongodb cluster

1. Available databases
show dbs

2. List the available collections
show collections

3. List the available commands and help
help

4. Create a Collection
db.createCollection(“datadotz”, { size: 1048576 } )

5. Show the collections
show collections

6. Delete a Collection
db.getCollection(“datadotz”).drop()

7. To know what database we are using
db

8. Inserting into a database
db.employee.insert({pid:’1′,name:’alex’,drug:’avil’,tot_amt:100})
db.employee.insert({pid:’2′,name:’gowtham’,drug:’Paracetamol’,tot_amt:200})
db.employee.insert({pid:’3′,name:’Ram’,drug:’metacin’,tot_amt:300})
db.employee.insert({pid:’4′,name:’saravanan’,drug:’metacin’,tot_amt:400})
db.employee.insert({pid:’5′,name:’senthil’,drug:’Avil’,sex:’male’,tot_amt:500})
db.employee.insert({pid:’6′,name:’siva’,drug:’avil’,tot_amt:600})

9. Display all the details in the database
db.test.find()

10. Update the entire document
db.test.update({name:’gowtham’}, {pid:’2′,name:’gowtham’,drug:’avil’,tot_amt:100})

11. Delete the document in the collection
db.test.remove({name:’gowtham’})

———————————–

Article written by DataDotz Team

DataDotz is a Chennai based BigData Team primarily focussed on consulting and training on technologies such as Apache Hadoop, Apache Spark , NoSQL(HBase, Cassandra, MongoDB), Search and Cloud Computing.

Note: DataDotz also provides classroom based Apache Kafka training in Chennai. The Course includes Cassandra , MongoDB, Scala and Apache Spark Training. For more details related to Apache Spark training in Chennai, please visit http://datadotz.com/training/