In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article shows you what the basic features and internal structure of MongoDB are. The content is concise and easy to understand. It will definitely make your eyes shine. I hope you can gain something through the detailed introduction of this article.
MongoDB is a product between relational database and non-relational database, which is the most feature-rich and most like relational database. The data structure it supports is very loose and is a bjson format similar to json, so it can store more complex data types. Mongo's biggest feature is that the query language it supports is very powerful, its syntax is a bit similar to object-oriented query language, almost can achieve most of the functions similar to relational database single table query, but also supports the establishment of indexes on data.
For most MongoDB users, MongoDB is like a big black box. However, if you can understand some of MongoDB's internal structure, it will help you better understand and use MongoDB.
BSON
In MongoDB, documents are abstractions of data that are used in Client and Server interactions. All clients (drivers in various languages) use this abstraction, which takes the form of what we often call BSON (Binary JSON).
BSON is a lightweight binary data format. MongoDB is able to use BSON and store BSON on disk as storage for data.
When the Client wants to write a document and use queries, it needs to encode the document into BSON format and then send it to the Server. Similarly, the return result from the Server side is also encoded in BSON format and returned to the Client side.
The BSON format is used for three purposes:
Efficiency. BSON is designed for efficiency and uses very little space. Even in the worst case, the BSON format is more storage efficient than the JSON format in the best case.
Transmissibility. In some cases, BSON sacrifices extra space to facilitate data transmission. For example, the transmission prefix of a string identifies the length of the string, rather than putting an end tag at the end of the string. This form of transmission facilitates MongoDB to modify the transmitted data.
Performance. Finally, the encoding and decoding of the BSON format are both very fast. It uses a C-style representation of data that can be used efficiently in a variety of languages.
write protocol
The Client side accesses the Server side using the lightweight TCP/IP write protocol. This protocol is described in detail in the MongoDB Wiki, which is actually a simple wrapper over BSON data. For example, the command to write data contains a 20-byte header (consisting of the length of the message and the write command ID), the name of the Collection to be written, and the data to be written.
data file
In the data folder of MongoDB (the default path is/data/db), all the files that make up the database are stored. Each database contains a.ns file and a number of data files that increase in number as the amount of data increases. So if there is a database named foo, then the files that make up foo will consist of foo.ns, foo.0, foo.1, foo.2, and so on.
Each time a data file is added, the size will be twice that of the previous data file, and each data file can be up to 2G. Such a design is conducive to preventing the database with small data volume from wasting too much space, while ensuring that the database with large data volume has corresponding space to use.
MongoDB uses preallocation to ensure stable write performance (this can be turned off with-noprealloc). Preallocation occurs in the background, and each preallocated file is padded with zeros. This allows MongoDB to keep extra space and spare data files at all times, thus avoiding congestion caused by allocated disk space due to data growth too fast.
Namespaces and extents
Each database consists of multiple namespaces, each of which stores data of a corresponding type. Each Collection in the database has its own namespace, as do index files. Metadata for all namespaces is stored in.ns files.
The data in the namespace is divided into multiple extents on disk, called extents. In the figure below, foo contains three data files, and the third data file is an empty preallocation file. The first two data files are divided into corresponding extents corresponding to different namespaces.
The figure above shows the characteristics associated with namespaces and extents. Each namespace can contain multiple distinct extents that are not contiguous. Just as data files grow, the extent size of each namespace grows with the number of allocations. The goal here is to balance the wasted space of namespaces with the continuity of data within a namespace. There is also a namespace to note in the above image: $freelist, which is used to record extents that are no longer in use (deleted collections or indexes). Whenever a namespace needs to allocate a new extent, it checks to see if $freelist has an appropriately sized extent available.
Memory mapped storage engine
MongoDB currently supports memory mapping engines. When MongoDB starts, all data files are mapped into memory, and the operating system hosts all disk operations. This storage engine has several characteristics:
The code for memory management in MongoDB is very lean, since the work is already hosted by the operating system.
The virtual memory used by the MongoDB server will be enormous and will exceed the size of the entire data file. Don't worry, the operating system will handle it. It should be noted that MongoDB itself does not manage memory, cannot specify memory size, and is completely managed by the operating system, so sometimes it is uncontrollable. In production environments, memory usage must be monitored at the OS level.
MongoDB has no control over the order in which data is written to disk, which would prevent MongoDB from implementing the writeahead log feature. So, if MongoDB wants to provide a durability feature, it needs to implement another storage engine.
MongoDB servers on 32-bit systems can only use 2 gigabytes of data files per instance of Mongod. This is because address pointers can only support 32 bits.
characteristics
It is characterized by high performance, easy deployment, easy use, and very convenient storage of data. The main functional characteristics are:
Collection-oriented storage, easy to store object type data.
Mode freedom.
Dynamic query support.
Full indexing, including internal objects.
Support queries.
Supports replication and failover.
Use efficient binary data storage, including large objects such as video.
Automate fragmentation to support scalability at the cloud computing hierarchy
Support RUBY, PYTHON, JAVA, C++, PHP and other languages.
File storage format is BSON (an extension of JSON)
accessible over a network
Collection-Orented means that data is stored in groups in a dataset, called a collection. Each collection has a unique identification name in the database and can contain an unlimited number of documents. The concept of a set is similar to that of a table in a relational database (RDBMS), except that it does not require any schema to be defined.
Schema-free means that we don't need to know any structural definition of a file stored in the mongodb database. If desired, you can store files with different structures in the same database.
Documents stored in collections are stored as key-value pairs. Keys are used to uniquely identify a document and are string types, while values can be complex file types. We call this storage format BSON (Binary Serialized dObject Format).
What are the basic features and internal structure of MongoDB? Have you learned any knowledge or skills? If you want to learn more skills or enrich your knowledge reserves, please pay attention to the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.