Introduction to Mongo DB
With the increase in the usage of Handheld devices, the amount of data being generated is increased exponentially. With the increase in data generation, comes the problem of data storage and scaling. Developers of Backend software development companies all over the world are facing difficulty in storing this large amount of data. Since the traditional databases are unable to cope up with the increasing data storage requirements they are now left with two main options, i.e. Either to Scale-up or Scale-out. Scale-up basically means buying a Bigger machine that has the potential to store a large amount of data and scaling-out is splitting of data across various machines. However, due to the Heavy costs of these bigger machines, Scaling-up could be done only up to a certain limit. So, there is now an urgent need to go for a scale-out option for our databases and this is where MongoDB comes into Picture.
Table of Content
Before Diving deep into the basics of MongoDB, a Fair understanding of NoSQL database is Paramount. NoSQL which basically stands for ‘not only SQL’ is a Non-Relational Database. It encompasses a wide variety of data models. They are typically used for working with large sets of Distributed data. NoSQL is majorly used in an application as where the need of scalability and performance outweighs the need for data consistency.
MongoDB was essentially designed in the Mid-2000s to scale-out the Databases. It is a document-oriented model classified under NoSQL database which allows splitting the data automatically across different servers. Every Database in MongoDB contains collections. These collections, in turn, contains documents. The size and content of documents can be different from each other. Unlike Relational databases, there is no need for defining the schema beforehand. Data Models available within the MongoDB enables the storage of complex structures, Hierarchical relationships, and arrays.
Commonly used Terms in MongoDB
_id - Every MongoDB document contains this a unique Value and is generated by default along with the creation of Document. It is like a primary key of the Document.
Collection - Collection refers to the grouping of MongoDB documents. It is equivalent to the table in the relational database.
Document - Record in MongoDB Collection is known as Document. It is Row equivalent in RDBMS which contains Field names and Values.
Field - Name-value pair in the document is called as Field. It is similar to Columns in RDBMS.
Example of Field with Key value pair
|CustomerID : 11|
Cursor- Pointer to the collection of documents returned is called cursor in MongoDB.
Advantages and Features of MongoDB
Document Oriented- Data is stored in a document instead of relational schema. This makes it more flexible and adaptable to real-time business requirements.
Ad hoc queries- We can easily retrieve specific fields from the documents. Searching by field, regular expressions, and range queries are possible with MongoDB.
Indexing- Any field in a MongoDB document can be indexed which in turn improves the performance of search in MongoDB.
Replication- MongoDB maintains two sets of replica primary and secondary, which ensures high availability. Replica contains one or more instances of MongoDB.
Load balancing- In MongoDB concept of sharding to scale horizontally by splitting data across multiple MongoDB instances. Because of the ability to run over multiple servers, balancing the load or data duplication in MongoDB can possibly be achieved. This helps to keep the system up and running despite having hardware failure.
Node.js uses asynchronous programming. For instance, while requesting a file, it will send the task to the computer file system. Unlike PHP or ASP, it does not wait for the file system to open and read the file. Rather it is ready to handle the next request. once the file system has opened and reads the file, the server returns the content to the client. Thus Node.js eliminates the waiting time.
Planning to Hire Blockchain Development Company ?
Features of Node.js
Event-driven- which means that everything that happens in Node is in reaction to an event. For example, when a new request comes in the server will start processing it. If it then encounters a blocking I/O operation, instead of waiting for this to complete, it will register a callback before continuing to process the next event.
Speed- Rich library of Node.js helps in very fast execution of code.
Single Threaded but Highly Scalable- It uses a single thread model to handle multiple concurrent requests. It uses event looping, which helps the server to respond in a non-blocking way, making it highly scalable unlike traditional servers
No Buffering- there is no buffering of data in Node.js. Applications simply shows the result of data in chunks.
Why Use Node.Js?