- Web Development with MongoDB and NodeJS(Second Edition)
- Mithun Satheesh Bruno Joseph D'mello Jason Krol
- 481字
- 2021-07-09 21:12:59
A short introduction to MongoDB
As we discussed in the previous paragraph, MongoDB falls into the document store category of NoSQL databases. MongoDB is being actively developed by 10gen, which was later renamed to MongoDB I.inc. MongoDB is open source and its source is available on various platforms such as GitHub.
Features of MongoDB
One of the most important reasons for the popularity of MongoDB is that it is a JSON-friendly database. It means that documents are stored and retrieved from MongoDB as JavaScript objects. Internally, this JSON data gets converted to BSON format while getting persisted to the system. So, this gives an extreme flexibility where we can use the same data format from client to server and eventually to the database.
A typical document (record) in a MongoDB collection (table) might look like the following code:
$ mongo > db.contacts.find({email: 'jason@kroltech.com'}).pretty() { "email" : "jason@kroltech.com", "phone" : "123-456-7890", "gravatar" : "751e957d48e31841ff15d8fa0f1b0acf", "_id" : ObjectId("52fad824392f58ac2452c992"), "name" : { "first" : "Jason", "last" : "Krol" }, "__v" : 0 }
Another important feature of MongoDB is its schemaless nature. With a relational database, you are required to define (ahead of time) the exact structure of the data being stored, which is termed as the schema. This means that you must have defined the exact number of columns, length, and data type for every field in a table, and that each field must always match that exact set of criteria. Mongo provides a flexible nature where the documents that you store into the database need not follow any schema unless the developer enforces it through the application level. This makes MongoDB a great fit for Agile-based development, as you could carry out modifications on the application schema on fly.
Other than the JavaScript-friendly nature, one other resemblance of MongoDB with Node.js is that it is also designed with highly concurrent applications with heavy read operations in mind.
MongoDB also introduces the concept of sharding, which makes it possible to scale the database horizontally as well as vertically. If the application owner needs to increase the database capabilities, they could add up more machines into the stack. This is a cheaper option compared to investing on RAM of a single machine, which will be the case in RDBMS solutions.
All the advantages that we discussed come with some impact on the consistency, as MongoDB does not strictly adhere to the RDBMS standards like ACID transactions. Also, if you end up creating a data model that might need too many JOIN operations, then MongoDB won't make a good fit as it is not designed with too many aggregations even though the aggregations are possible via the MongoDB aggregation framework. MongoDB may or may not be the right solution for your application. You should truly weigh the pros and cons of each technology before making a decision to determine which technology is right for you.
- Objective-C Memory Management Essentials
- 深入淺出Prometheus:原理、應用、源碼與拓展詳解
- Ext JS 4 Web Application Development Cookbook
- 微信小程序入門指南
- 從零開始學C#
- Python+Tableau數據可視化之美
- Java Fundamentals
- Android移動開發案例教程:基于Android Studio開發環境
- Python機器學習之金融風險管理
- Clojure Polymorphism
- Mastering OpenStack
- PHP典型模塊與項目實戰大全
- 秒懂算法:用常識解讀數據結構與算法
- Illustrator CS6中文版應用教程(第二版)
- OpenStack Sahara Essentials