MongoDB
In this article, we will discuss about NoSQL, the basics of mongoDB and how to do CRUD operations in mongoDB.MongoDB
What is NoSQL?
NoSQL is also known as “not only SQL”. They are non-tabular databases. They store data in a different manner than SQL databases. These kinds of databases come in various types based on their data model, such as document, key-value, wide-column, and graph. They are more flexible, scalable, distributed databases. Most of the NoSQL databases are open source.
There are mainly four types of NoSQL database systems that exist. Each of them uses different types of data models.
- Document databases
- Graph databases
- Key-value stores
- Wide-column stores
Advantages of NoSQL
- The workload for interactive real-time web applications is simplified.
- NoSQL caters to flexibility for data that is not normalized and requires flexible data models.
- They provide great scalability for large data sets.
- They are greatly suited for cloud applications, mobile, and big data requirements.
Disadvantages of NoSQL
- NoSQL has its own querying languages. Which is in contrast to SOL.
- As NoSQL databases are newer, there are no standards as relational databases.
- There is no such schema as relational databases have.
What is MongoDB?
MongoDB is a No SQL database. It is an open-source, cross-platform, document-oriented database written in C++.
MongoDB was developed by a NewYork based organization named 10gen which is now known as MongoDB Inc. It was initially developed as a PAAS (Platform as a Service). Later in 2009, it is introduced in the market as an open source database server that was maintained and supported by MongoDB Inc.
Instead of storing data in tables like SQL, each record in MongoDB is stored in collections. There is a slight terminology difference between the relational database and MongoDB, they are as follows.
Here’s a sample Document from a MongoDB collection.
The primary purpose of building MongoDB
- Scalability
- Performance
- High Availability
- Provides high performance.
- Scaling from single server deployments to large, complex multi-site architectures.
- Key points of MongoDB
- Develop Faster
- Deploy Easier
Features of MongoDB
- Support ad hoc queries
- Indexing
- Replication
- Duplication of data
- Load balancing
- Database Triggers
MongoDB Advantages
- MongoDB is schema less. It is a document database in which one collection holds different documents.
- There may be difference between number of fields, content and size of the document from one to other.
- Structure of a single object is clear in MongoDB.
- There are no complex joins in MongoDB.
- MongoDB provides the facility of deep query because it supports a powerful dynamic query on documents.
- It is very easy to scale.
- It uses internal memory for storing working sets and this is the reason of its fast access.
MongoDB Datatypes
Let’s move to the CRUD functions in mongoDB…
Get Gowsigan Pushpanathan’s stories in your inbox
Join Medium for free to get updates from this writer.
Create Operation
There are two ways to insert data to the MongoDB. We’ll use the RecordsDB collection in this example.
- insertOne() => To add single data to the collection
2. insertMany() => To add multiple data to the collection.
Read Operation
As in Create there are two ways to retrieve data from the MongoDB.
- find() =>To get all data from the collection.
db.RecordsDB.find()
2. findone() => To get single data that satisfies search criteria.
syntax : db.{collection}.findOne({query}, {projection})
when we run this code we will get the below output. db.laliga.find({“age”:34})
Update Operation
There are 3 ways to update data in MongoDB.
- updateOne() => Updating existing single data
2. updateMany() => Updating existing multiple data
3. replaceOne() => Replace a single data from MongoDB
Delete Operation
There are two ways to delete data from the MongoDB.
- deleteOne() => used to remove single data
db.laliga.deleteOne({name:”Kylian Mbappe”})
2. deleteMany() => used to remove multiple data
db.RecordsDB.deleteMany({team:”FC Barcelona”})
Conclusion
By using this article, you learned NoSQL and the notation of CRUD operations using mongoDB and the characteristics of mongoDB.
Thank you so much for reading my article and I hope you have a better idea from this article.
Thank you.









