MongoDB Basics

What is NoSQL?

   Non-relational database, sometimes referred to as the abbreviation of Not Only SQL, is a general term for database management systems that are different from traditional relational databases.


 

Advantages of NoSQL

     1. High scalability

     2. High concurrency, strong reading and writing ability under big data

     3. Distributed Computing

     4. Handling massive amounts of data

     5. No complicated relationships


Four families of NoSQL databases

    Column store: Hbase

    Key-Value storage: Redis

    Image storage: Neo4J 

    Document Storage: MongoDB 

    MongoDB stores data as a document, and the data structure consists of key-value (name=>value) pairs. MongoDB documents are similar to JSON objects. Field values ​​can contain other documents, arrays, and arrays of documents.


MongoDB和JSON、BSON

    JSON: is a syntax for storing and exchanging textual information. Similar to XML. JSON database statements can be easily parsed.

    BSON: Binary JSON, a binary encoding storage format for JSON documents. BSON has data types that JSON does not have: Date and BinData. Documents in MongoDB are stored in the form of BSON.


MongoDB documents support different data types


{
  name:"Jone Doe",
  title:"software developer", #string
  address:{
           street:"123 45th street"
   state:"new York"
   zipcode:10036
  
          }, #nested document
   expertise:["MongoDB","Python","Javascript"], #数组
   employee_number:320,       #×××
   location:[53.34,-6326]  #Geo-spatial
}
}


Key features of MongoDB:

    1. High performance 

    2. Rich query language

    3. High availability

           Replica sets, automatic failover, data redundancy


image.png


    4. Horizontal scalability

    5. Support multiple storage engines

           MMAPv1 storage engine: <3.2 Default storage engine is MMAPv1

           WirdeTiger storage engine: >=3.2 The default storage engine is WiredTiger

            In-Memory storage engine: Changed in version 3.2.6

                                                                                                 Comparison of storage engines

image.png


MongoDB的GridFS


                                                                                     GridFS

image.png



MongoDB and RDBMS data structure logic comparison

image.png


Examples of practical application scenarios of MongoDB

game scene

    Use MongoDB to store game user information, user equipment, points, etc. are directly stored in the form of embedded documents, which is convenient for query and update.

Logistics scene

    Using MongoDB to store order information, the status of the order will be continuously updated during the shipping process. It is stored in the form of an embedded array in MongoDB, and all changes to the order can be read out with one query.

social scene

    Use MongoDB to store and store user information, as well as the circle of friends information published by users, and implement functions such as nearby people and places through geographic location indexing


IoT Scenario

    Use MongoDB to store all connected smart device information, as well as log information reported by the device, and perform multi-dimensional analysis on this information.

live video

    Use MongoDB to store user information, gift information, etc.


The choice of MongoDB version, it is now recommended to use version 3.4

MongoDB is divided into enterprise edition and community edition. The community edition supports the use of MongoDB ops manager


image.png


Whether to use MongoDB

image.png


If there is 1 Yes above, you can consider MongoDB, 2 or more Yes, you will never regret choosing MongoDB!!!


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324690924&siteId=291194637