MongoDB is the best database to use in 2023, I know you think not so let's debunk that myth together.
MongoDB is a NoSQL document oriented database built by the MongoDB Inc.
MongoDB was founded in 2007 by Dwight Merriman, Eliot Horowitz and Kevin Ryan. These guys had an Internet advertising company called DoubleClick (which is now owned by Google).
The business served 400,000 ads per second, but often struggled with scalability and agility issues. The team was inspired to create a database that tackled the challenges facing DoubleClick. The solution is what we now call MongoDB.
MongoDB was initially realeased to the public on February 11, 2009.
MongoDB is written in C++, JavaScript and Python. You can find the link to the official repository in the description.
MongoDB stores data in the form of JSON like objects, however MongoDB stores our data using BSON which stands for Binary JSON.
BSON is a binary-encoded serialization of JSON documents.
BSON is derived from JSON but BSON supports more complex data type like dates and binary data. BSON was created by the MongoDB team specifically for use on MongoDB. BSON is the format used both for data storage and network transfer in MongoDB.
Hello Devs welcome back, in today's lesson we are going to explore the MongoDB database shortly. We will consider the following in this article
- How the MongoDB database works and how it is different from traditional SQL databases.
- Features of MongoDB.
- How to get started with MongoDB.
How it works
Let's see how the MongoDB database works.
In a MongoDB database you have documents and collection both of which are stored inside of a database. Think of a document as a single JSON file with multiple key-value pairs. Similar documents are stored in a collection while multiple collections are stored in a database. This approach is different from a traditional SQL database where data is stored using tables and rows.
If we want to relate MongoDB to an SQL databases we'd say documents are to rows as collection are to tables. In an SQL database a table stores the fields for our data while rows stores the values for each field. In MongoDB each document has it's own field which stores it's own value. You see the difference? fields are defined on documents and not collections. Collections just serve as a way to group related documents.
MongoDB also has it's own query language called the MongoDB query language (MQL) MongoDB is largely suited to unstructured data or data with loosely defined relationship. You also store related data in a MongoDB database you'd just use a different approach than what you'd use in an SQL database.
Every document is provided with an ID by default when it created. We can add our data as key value pairs on the document. MongoDB supports an optional schema that enforces a particular structure on the documents inside a collection.
Features of MongoDB
Here are some of the features Mongodb offers to developers
The first feature of MongoDB we'll look at is horizontal scaling 👇👇
MongoDB supports horizontal scaling, this is achieved by using horizontal partitioning with a shard key, The shard key is selected by the user and it determines how the data in a collection will be distributed. MongoDB handles load balancing across different shrads automatically with very little to no effort on your part.
A cool feature of MongoDB is that it will automatically replicate and distribute copies of our document stored in each collection. This ensures that there will always be at least two copies of a document, any of which can serve as the primary source for read or write operations. MongoDB will manage the different data sources to ensure that each time we get consistent data when making read or write operation.
MongoDB allows us to perform aggregation queries, these aggregations are complex queries that are similar to compound queries in SQL. Multiple documents can be aggregated to one value inside a single read operation.
MongoDB can also execute JavaScript code when making these aggregation and simple queries. The JavaScript code is executed directly in the database.
And finally,
MongoDB allows us to cap the max total size for a collection.
MongoDB is used by popular companies like Forbes, Toyota, Sanoma etc.
To get started with MongoDB, create a free account to start using MongoDB Atlas. Atlas is a managed MongoDB instace all setup and running in the cloud for you
MongoDB has drivers for your favorite programming language so you can go ahead and install the drivers for your popular programming Language and start building your next project you probably won't finish with MongoDB.
Top comments (0)