English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
MongoDB is a cross-platform, document-oriented database that provides high performance, high availability, and scalability. MongoDB is committed to the concepts of collection and document.
MongoDB is a database program, MongoDB is written in C ++written in language.
Free (Not only SQL) – You do not have to pay anything for using it in your application.
Open Source (Not only SQL) – Open source is open, and the open source community has contributed to the development of the MongoDB database program.
Cross-Platform (Not only SQL) – MongoDB is built on a platform (such as Linux) and can run on other platforms (Windows, MacOS, etc.) without any modification to the code.
Document-Oriented (Not only SQL) – MongoDB stores records (such as documents) in JSON format. This has many advantages. A significant advantage is that adding new features to the database (columns in relational databases) does not require any trouble.
NoSQL(Not only SQL) – MongoDB uses a document-based database where each document is a key with complex values. The document value can contain multiple key-value pairs.
A database is a physical container for collections. Each database has its own file set on the file system. A MongoDB server typically has multiple databases.
A collection is a set of MongoDB documents. It is equivalent to an RDBMS table. Collections exist within a single database. Collections do not enforce a schema. Documents in a collection can have different fields. Typically, all documents in a collection have similar or related purposes.
A document is a set of key-value pairs. Documents have a dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same fields or structure sets, and the common fields in the collection documents can store different types of data.
The following table shows the relationship between RDBMS terminology and MongoDB.
Relational Database Management System | MongoDB |
---|---|
Database | Database |
Table | Collection |
Tuple/Row | Document |
Column | Field |
Table Join | Embedded Document |
Primary Key Constraint | Primary Key (the default key _id provided by MongoDB itself) |
Database Server and Client | |
mysqld / Oracle | mongod |
mysql / sqlplus | mongo |
The following examples show the document structure of a blog site, which is just a comma-separated key-value pair.
{ 7df78ad8902c) title: 'MongoDB Overview', description: 'MongoDB is a NoSQL database', by: '基础教程', url: 'https://www.oldtoolbag.com tags: ['mongodb', 'database', 'NoSQL'], likes: 100, comments: [ { user: 'user1', message: 'My first comment', dateCreated: new Date(2011,1,20,2,15, like: 0 } { user: 'user2', message: 'My second comments', dateCreated: new Date(2011,1,25,7,45, ) 5 ] like: ]
}_id12is a12of the bytes are the hexadecimal digits of the byte, which ensure the uniqueness of each document. You can provide an id when inserting a document. If not provided, MongoDB will provide a unique id for each document. This4bytes are used for the current timestamp, followed by3bytes are used for the machine id, followed by2bytes are used for the process id of the MongoDB server, the remaining3A byte is a simple increment value.