MongoDB is a general-purpose, document-based distributed database, which is a product that falls between a relational database and a non-relational (NoSQL) database. It is the most feature-rich and relational-database-like among non-relational databases.

An example of a MongoDB document

{
  "_id": "5cf0029caff5056591b0ce7d",
  "firstname": "Jane",
  "lastname": "Wu",
  "address": {
    "street": "1 Circle Rd",
    "city": "Los Angeles",
    "state": "CA",
    "zip": "90404"
  },
  "hobbies": ["surfing", "coding"]
}

Nothing special, just a piece of JSON data. The document data stored in MongoDB is similar to this JSON data. Due to the storage of JSON data, the data format stored in MongoDB is very flexible. Unlike MySQL, which must have a fixed table structure, this means that you can add or delete fields at any time, and the speed is also very fast.

Tip: If your business does not have high requirements for complex transactions, joins, and data consistency, and you simply pursue fast data read and write, high concurrency, flexible and free storage formats, and do not need to define table structures in advance, MongoDB is a good choice.

Characteristics of MongoDB

High performance

MongoDB provides high-performance data persistence. In particular,

  • Using an embedded data model can reduce I/O operations of the database system.
  • It supports indexing, so query efficiency is very high, and indexed fields can be fields of embedded documents or keys of arrays.

Rich query language

MongoDB supports a rich set of query expressions to meet various business query scenarios.

Support for geospatial queries

For O2O businesses and location-related businesses, frequent geospatial queries are needed, such as querying nearby stores, nearby people, or determining if you are in a commercial district. All of these require geospatial retrieval support.

High availability

MongoDB's replica set provides:

  • Automatic failover
  • Data redundancy

A replica set is a group of mongod instances that maintain the same data set, providing data redundancy and high availability support.

Horizontal scalability

MongoDB supports horizontal scaling. By using sharding, data is distributed across a cluster of machines.