# 介绍

## 目录

* [文档数据库](/mongodb/introduction.md#document-database)
* [核心特性](/mongodb/introduction.md#key-features)
  * [高性能](/mongodb/introduction.md#high-performance)
  * [丰富的查询语言](/mongodb/introduction.md#rich-query-language)
  * [高可用](/mongodb/introduction.md#high-availability)
  * [水平扩展](/mongodb/introduction.md#horizontal-scalability)
  * [支持多种存储引擎](/mongodb/introduction.md#support-for-multiple-storage-engines)

MongoDB 是一个高性能，高可用，自动伸缩的开源数据库。

## Document Database

MongoDB的一行记录叫做一个文档（相当于MySQL的一行）， 这个文档是一种键值结构，类似于JSON类型。这个键对应的值既可以是字符串，数组或者是其它文档(即文档的嵌套)。

使用文档类型（document）的优点如下：

* 文档这种类型在众多编程语言中比较贴近于原始数据
* 文档的嵌套可以减少合并（join）这种操作带来的昂贵开销
* Dynamic schema supports fluent polymorphism

## Key Features

### High Performance

MongoDB 提供高性能的数据存储，尤其是：

* 支持嵌套的数据模型，减少IO操作带来的损耗
* Indexes support faster queries and can include keys from embedded documents and arrays.

### Rich Query Language

MongoDB 支持丰富的读写操作（[CRUD](https://docs.mongodb.com/manual/crud/)），比如：

* [数据聚合](https://docs.mongodb.com/manual/core/aggregation-pipeline/)
* [文本搜索](https://docs.mongodb.com/manual/text-search/)和[位图查询](https://docs.mongodb.com/manual/tutorial/geospatial-tutorial/)（ Geospatial Queries）

### High Availability

高可用的代表是MongoDB的副本集（replica set），提供：

* 自动故障转移
* 数据冗余（因为备份了数据，所以肯定会产生冗余）

副本集是一组维护者相同数据集的mongod进程，从而增加了数据的可用性（丢失概率小）

### Horizontal Scalability

MongoDB把水平扩展（即分片）作为它的核心功能之一：

* [Sharding](https://docs.mongodb.com/manual/sharding/#sharding-introduction) distributes data across a cluster of machines
* Starting in 3.4, MongoDB supports creating [zones](https://docs.mongodb.com/manual/core/zone-sharding/#zone-sharding) of data based on the shard key. In a balanced cluster, MongoDB directs reads and writes covered by a zone only to those shards inside the zone. See the Zones manual page for more information

### Support for Multiple Storage Engines

MongoDB支持以下的存储引擎：

* [WiredTiger Storage Engine](https://docs.mongodb.com/manual/core/wiredtiger/) (including support for [Encryption at Rest](https://docs.mongodb.com/manual/core/security-encryption-at-rest/))
* [In-Memory Storage Engine](https://docs.mongodb.com/manual/core/inmemory/)
* [MMAPv1 Storage Engine](https://docs.mongodb.com/manual/core/mmapv1/) (MongoDB 4.0被移除)

另外，MongoDB还提供了可插拔的存储引擎API，允许第三方自己开发存储引擎


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://xiehongxin.gitbook.io/mongodb/introduction.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
