MongoDB CRUD Operation
MongoDB is a document-oriented database used to store and process data in the form of documents.MongoDB provides some basics but essential operations that we can easily interact with MongoDB servers. The basics of operation are
Document: Documents are basically just an object nothing else, like a row in SQL based database system.
Collection: Collections in MongoDB likes tables in the SQL database. They are collections of documents. If a collection doesn't exist in the database, then it will create automatically a new collection in the database.
1. Create:
This involves writing / inserting data into the database. MongoDB provides the following methods to insert documents into a collection: In this case the document we will insert a simple JSON object
- db.collection_name.insertOne(document)
- db.collection_name.insertMany(document)
2. Read:
which query used to retrieve data from a database
- db.collection_name.find()
That find( ) method has 2 optional parameters.
find(query, projection)
3. Update:
which change data that already exists in a database. You can update the documents in your database with following commands.
- db.collection_name.updateOne( )
- db.collection_name.updateMany( )
With parameters:
db.collection.updateOne(filter, update)
- db.collection.deleteOne( )
- db.collection.deleteMany( )