Part I basic chapter III MONGODB architecture

Source: Internet
Author: User
Tags mongodb server

Statement: The article is mainly from the "MongoDB actual Combat" a book, the main want to learn MongoDB knowledge through the book, deepen understanding, so write in their own blog, as a record, in the final chapter, there will be a collection of MongoDB database application Java EE Web application.

MongoDB is a portable database, it can be used on every popular platform, that is, the so-called cross-platform, although slightly different operating systems, but from the overall architecture, MongoDB on different platforms are the same, such as data logical structure and data storage and so on.

A running MongoDB database can be thought of as a MongoDB server, which consists of an instance and a database, and in general, a MongoDB server machine contains one instance or multiple corresponding databases, but in special cases, such as hardware input costs or special application requirements, you can also allow multiple instances or multiple databases on a single server machine.

The collection of a series of physical files (data files, log files, etc.) in MongoDB is referred to as the database, in other words, the database is composed of a series of physical files that are related to the disk.


3.1. Logical structure of data

Many people will encounter a variety of problems when learning MongoDB architecture, I am here to give you a simple introduction of the structure of one of MongoDB architecture, the logical structure of MongoDB is a hierarchy, mainly by: Document, Collection ( Collection), the database is composed of three parts, the logical structure is user-oriented, the user uses MongoDB development application is the logical structure.

    • A MongoDB document, which is equivalent to a row of records in a relational database.
    • Multiple Documents form a collection (Collection), which is equivalent to a table of relational databases.
    • Multiple collections (Collection), expanded and organized together, is the database.
    • A MongoDB instance supports multiple databases (database).
A hierarchy of documents, Collections (Collection), databases (database) such as:

for friends who are accustomed to relational databases, I compare MongoDB with the logical structure of relational databases in order to give you a deeper understanding of the logical structure of MongoDB:

3.2. Data storage structureMongoDB is new to domestic users, it's like a black box, but if you know more about its internal data storage, you'll quickly understand and harness mongodb to make it more effective. The default data directory for MongoDB is/daba/db, which is responsible for storing all mongodb data files, inside MongoDB, Each database contains an. ns file and some data files, and these files become more and more as the amount of data increases, so if there is a database called Foo in the system, the files that make up the Foo database will be made up of FOO.NS, foo.0, Foo.1, Foo.2, such as the composition, specific as follows:
MongoDB has a pre-allocated space mechanism, each of the pre-allocated files are filled with 0, because of this mechanism, MongoDB always maintain extra space and spare data files, so as to effectively avoid the data explosion caused by the disk pressure is too large problem. due to the increase in the amount of data in the table, the data file is allocated twice times the size of the previous data file, and each data file has a maximum of 2G, which helps to prevent the smaller database from wasting too much disk space while ensuring that the larger database has the appropriate reserved space for use. Each table in the database corresponds to a namespace, and each index has a corresponding namespace, and the metadata for those namespaces is set in the *.ns file. in the. Foo This database contains 3 files for storing tables and index data, foo.2 files are pre-allocated empty files, foo.0 and foo.1 the two data files are divided into corresponding extents corresponding to different namespaces.
Shows the relationship of namespace and disk, each namespace can contain several different extents, which are not contiguous, the same as the growth of the data file, each namespace corresponds to the size of the extents are increasing as the number of allocations, The purpose of this is to balance the wasted space of namespaces with the continuity of data in a given namespace, and there is a namespace to be aware of: $freelist, this namespace user records the extents that are no longer used (collection or indexes that are deleted). Whenever the command space needs to allocate new extents, it will first see if the $freelist has the right size to use, thus reclaiming free disk space.

Part I basic chapter III MONGODB architecture

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.