CRUD operations in MongoDB using Java

By Narmada Yalagandula

MongoDB is document oriented  database . It  provides high performance, high availability, and easy scalability. It stores data in JSON like documents  instead of tables and records as in RDBMS. The basic unit of data in MongoDB is document comprising key-value pairs. Collections are sets of documents and function as tables in RDBMS.

Here , I present how  to connect to MongoDB using java and perform CRUD operations on the Mongo database collections.

We connect to MongoDB adding MongoDB driver as a dependency in pom.xml file.

Sample code to connect and perform CRUD operations on MongoDB


In the output an unique _id is created for the document inserted.