The trending technology in web application development is MEAN Stack Development (MongoDB ExpressJS AngularJS NodeJS). One language development journey makes it distinct from the other technologies. We will be going to understand each component in MEAN in detail in the explicit parts. Let us know about MongoDB here:
The capacity to store and render the data is the most important part for most applications. In the MEAN stack, the database of choice is MongoDB, the M in MEAN. MongoDB fits into the stack incredibly well. Like Node.js, it’s renowned for being fast and scalable.
Relational versus document databases:
If you’ve used a relational database before, or even a spreadsheet, you would be used to the concept of columns and rows. Typically, a column defines the name and data type and each row would be a different entry. Refer Table 1.1 for an example.
MongoDB is not like that! MongoDB is a document database. The concept of rows is there however columns are omitted from the picture. Instead of a column defining what should be in the row is treated distantly. Each row is a document, and this document both defines and holds the data itself. Refer Table 1.2 for how a collection of documents might be listed (the indented layout is for readability, not a visualization of columns).
Firstname: Middlename Lastname
“Steve” “Mark” “Beven”
Firstname: Middlename Lastname Nickname
“Brian” “Paul” “Clark” “Vicky”
This less-structured appearance implies that a collection of documents could have a huge variety of data inside. Let’s take a look at a sample document so that you will get a better idea of it.
More than just a document database
MongoDB sets itself differ from other document databases with its support for secondary indexing and rich queries. It allows you to create indexes on more than just the unique identifier field, and querying indexed fields is much faster. You can also create some fairly complex queries against a MongoDB database—not to the level of huge SQL commands with joins all over the place, but powerful enough for most of the cases. From Table 1.2- each document in a document database defines and holds the data, in no particular order.
What is MongoDB not good for?
MongoDB isn’t a transactional database, and it should not be used as such. A transactional database can take a number of separate operations as one transaction. If any one of the operations in a transaction fails the entire transaction fails, and none of the operations complete. MongoDB does not work like this. MongoDB takes each of the operations independently; if one fails then it alone fails and the rest of the operations will continue. This is important if you need to update multiple collections or documents at the same time. For example, If you’re building a shopping cart, you need to make sure that the payment is made and recorded, also the order is marked as confirmed to be processed. So these two operations need to be tied together in one transaction. Your database structure might allow you to do this in one collection, or you might code fallbacks and safety nets into your application logic in case one fails, or you might choose to use a transactional database.
Mongoose for data modeling and more
Mongo DB’s flexibility about what it stores in documents is a great thing for the database. But most applications need some structure to their data. Note that it’s the application that needs the structure, not the database. So where to define the structure of your application data? In the application itself! To this end, the company behind MongoDB created Mongoose. In their own words, Mongoose provides “elegant MongoDB object modeling for Node.js” (http:// mongoosejs.com/).
Conclusively, MongoDB is a great choice of database for most web applications because it maintains the balance between the speed of pure document databases and the power of relational databases. That the data is effectively stored in JSON makes it the perfect data store for the MEAN stack. We will get to know about other components in the upcoming parts.