├── 03 The mongo Shell mongo命令行 ├── 03-01 The mongo Shell mongo命令行.md ├── 03-02 configure-the-mongo-shell 配置mongo shell.md └── 03-03 access-the-mongo-shell-help 查看mongo shell帮助文档.md ├── 04 MongoDB CRUD Operations MongoDB CRUD 操作 ├── 04-01 MongoDB CRUD OperationsMongoDB中的CURD操作.md ├── 04-06 Bulk Write Operations 批量写操作.md ├── 04-11 Read Concern 读关注.md ├── 04-12 Write Concern 写关注.md ├── 04-13 MongoDB CRUD Concepts MongoDB 增删改查 概念.md └── 04-13-02 Read Isolation, Consistency, and Recency 读隔离性,一致性以及近因性.md ├── 06 Data Models 数据模型 ├── 06-01 Data Modeling Introduction 数据建模介绍.md └── 06-02 Schema Validation模式验证.md ├── 07 Transactions 事务 ├── 07-01 Transactions 事务.md └── 07-05 Transactions and Operations 事务操作.md ├── 08 Indexes 索引 ├── 08-01 Indexes索引.md ├── 08-02 Single Field Indexes单字段索引.md ├── 08-03 Compound Indexes复合索引.md ├── 08-07 2dsphere_Indexes 2dsphere索引.md ├── 08-10 Hashed Indexes 哈希索引.md ├── 08-11 Index Properties 索引属性.md ├── 08-12 Index Builds on Populated Collections 在集合上创建索引.md └── 08-15 Measure Index Use 度量索引使用情况.md ├── 09 Security 安全 ├── 09-01,02 Security&Security Checklist 安全&安全检查列表.md ├── 09-03 Enable Access Control 启用访问控制.md ├── 09-04 Authentication 身份验证.md ├── 09-09 Auditing 审计.md ├── 09-09-01 Configure-Auditing 配置审计.md ├── 09-09-02 Configure-Audit-Filters 配置审计过滤器.md ├── 09-09-03 System-Event-Audit-Messages 系统事件审计消息.md ├── 09-10 Network and Configuration Hardening 网络和配置强化.md ├── 09-12 Security Reference 安全参考.md ├── 09-12-01system.rolesCollection system.roles 集合.md ├── 09-12-02system.usersCollection system.users 集合.md ├── 09-12-03Resource Document 资源文档.md ├── 09-12-04 Privilege.Actions 权限操作.md ├── 09-14 Appendix 附录.md ├── 09-14-01 Appendix A - OpenSSL CA Certificate for Testing.md ├── 09-14-02 Appendix B - OpenSSL Server Certificates for Testing.md └── 09-14-03 Appendix C - OpenSSL Client Certificates for Testing.md ├── 11 Replication 复制 ├── 11-01 Replication 复制.md ├── 11-02 Replica Set Members 副本集成员.md ├── 11-03 Replica Set Oplog 副本集Oplog.md ├── 11-04 Replica Set Data Synchronization 副本集数据同步 .md └── 11-05 Replica Set Deployment Architectures 副本集部署架构.md ├── 12 Sharding 分片 ├── 12-03 Shard keys 分片键.md ├── 12-04 Hashed Sharding哈希分片.md ├── 12-05 Ranged Sharding范围分片.md └── 12-08-02 Split Chunks in a Sharded Cluster 在分片集群中拆分数据块.md ├── 13 Administration 管理 ├── 13-02 Production Notes 产品说明.md ├── 13-03 Operations Checklist 操作检查表.md ├── 13-04 Development Checklist开发清单.md ├── 13-05 Performance 性能.md ├── 13-06 Configuration and Maintenance配置和维护.md └── 13-08 MongoDB Backup Methods MogoDB 备份方法.md ├── 14 Storage 存储 ├── 14-01-01 WiredTiger Storage Engine WiredTiger存储引擎.md ├── 14-01-02 In-Memory Storage Engine 内存存储引擎.md └── 14-05 FAQ MongoDB Storage 常见问答:MongoDB存储.md ├── 15 Frequently Asked Questions 常见问题 ├── 15-01 FAQ MongoDB Fundamentals常见问题:MongDB基础知识.md ├── 15-02 FAQ Indexes常见问题:索引.md ├── 15-03 FAQ Concurrency常见问题:并发.md ├── 15-04 FAQ Sharding with MongoDB常见问题:使用MongoDB分片.md ├── 15-05 FAQ Replication and Replica Sets常见问题:复制和副本集.md ├── 15-06 FAQ MongoDB Storage常见问题:MongoDB存储.md └── 15-07 FAQ MongoDB Diagnostics常见问题:MongDB诊断.md ├── README.md └── docs └── readme.md /03 The mongo Shell mongo命令行/03-02 configure-the-mongo-shell 配置mongo shell.md: -------------------------------------------------------------------------------- 1 | # Configure the mongo Shell 配置mongo shell 2 | 3 | On this page 本页内容 4 | 5 | - Customize the Prompt[](https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/#customize-the-prompt) 自定义提示 6 | - Use an External Editor in the mongo Shell[](https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/#use-an-external-editor-in-the-mongo-shell)在mongo shell中使用外部编辑器 7 | - Change the mongo Shell Batch Size[](https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/#change-the-mongo-shell-batch-size)修改mongo shell 每次返回的结果集大小 8 | 9 | 10 | ## Customize the Prompt 自定义提示 11 | 12 | You may modify the content of the prompt by setting the variable prompt in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell. The prompt variable can hold strings as well as JavaScript code. If prompt holds a function that returns a string, mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) can display dynamic information in each prompt. 13 | 你可以在mongo shell中通过设置prompt变量来修改提示内容。prompt变量可以保存字符串和JavaScript代码。如果prompt中是一个返回值为字符串的函数,那么mongo可以在每次提示时动态显示信息。 14 | 15 | You can add the logic for the prompt in the .mongorc.js[](https://docs.mongodb.com/manual/reference/program/mongo/#mongo-mongorc-file) file to set the prompt each time you start up the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell. 16 | 可以通过在*.mongorc.js*文件添加逻辑来设置每次启动mongo shell时显示的提示。 17 | 18 | ### Customize Prompt to Display Number of Operations 自定义提示显示操作的数量 19 | 20 | For example,to create a mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell prompt with the number of operations issued in the current session, define the following variables in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell: 21 | 例如,要在当前会话中创建一个带有操作编号的提示,可以在mongo shell中按如下设置: 22 | 23 | ``` 24 | cmdCount = 1; 25 | prompt = function() { 26 | return (cmdCount++) + "> "; 27 | } 28 | ``` 29 | 30 | The prompt would then resemble the following:提示如下所示: 31 | 32 | ``` 33 | 1> 34 | 2> 35 | 3> 36 | ``` 37 | 38 | ### Customize Prompt to Display Database and Hostname 自定义提示以显示数据库和主机名 39 | 40 | To create a mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell prompt in the form of < database >@< hostname >$, define the following variables: 41 | 要按照`<数据库>@<主机名>$`的格式来创建一个mongo shell提示,可以进行如下定义: 42 | 43 | ``` 44 | host = db.serverStatus().host; 45 | 46 | prompt = function() { 47 | return db+"@"+host+"$ "; 48 | } 49 | ``` 50 | 51 | The prompt would then resemble the following: 52 | 提示如下所示: 53 | 54 | ``` 55 | test@myHost1$ 56 | ``` 57 | 58 | ### Customize Prompt to Display Up Time and Document Count 自定义提示以显示运行时间和文档数量 59 | 60 | To create a mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell prompt that contains the system up time and the number of documents in the current database, define the following prompt variable in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell: 61 | 要创建一个包含系统运行时间和当前数据库文档个数的mongo shell提示,可以如下所示进行定义: 62 | 63 | ``` 64 | prompt = function() { 65 | return "Uptime:"+db.serverStatus().uptime+" Documents:"+db.stats().objects+" > "; 66 | } 67 | ``` 68 | 69 | The prompt would then resemble the following: 70 | 提示如下所示: 71 | 72 | ``` 73 | Uptime:5897 Documents:6 > 74 | ``` 75 | 76 | ## Use an External Editor in the mongo Shell 在mongo shell中使用外部编辑器 77 | 78 | You can use your own editor in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell by setting the EDITOR[](https://docs.mongodb.com/manual/reference/program/mongo/#envvar-EDITOR) environment variable before starting the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell. 79 | 在启动mongo shell前,可以通过设置EDITOR环境变量来使用自己的编辑器。 80 | 81 | ``` 82 | export EDITOR=vim 83 | mongo 84 | ``` 85 | 86 | Once in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell, you can edit with the specified editor by typing edit < variable > or edit < function >, as in the following example: 87 | 在mongo shell中,你可以通过输入`edit< variable >`或者`edit < function >`来使用特定的编辑器进行编辑,如下所示: 88 | 1. Define a function myFunction: 定义一个方法*myFunction*: 89 | ``` 90 | function myFunction () { } 91 | ``` 92 | 2. Edit the function using your editor: 用自定义的编辑器编辑该方法: 93 | ``` 94 | edit myFunction 95 | ``` 96 | The command should open the vim edit session. When finished with the edits, save and exit vim edit session. 97 | 此命令会打开vim编辑器。当完成编辑时,保存并退出编辑器。 98 | 99 | 3. In the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell, type myFunction to see the function definition: 在mongo shell中,输入*myFunction*查看方法的定义: 100 | ``` 101 | myFunction 102 | ``` 103 | 104 | The result should be the changes from your saved edit: 105 | 可以看到编辑修改后的结果: 106 | ``` 107 | function myFunction() { 108 | print("This was edited"); 109 | } 110 | ``` 111 | 112 | NOTE 注意 113 | 114 | As mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell interprets code edited in an external editor, it may modify code in functions, depending on the JavaScript compiler. For example, mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) may convert 1+1 to 2 or remove comments. The actual changes affect only the appearance of the code and will vary based on the version of JavaScript used but will not affect the semantics of the code. 115 | 当mongo shell解释在外部编辑器中编辑的代码时,它可能会根据JavaScript编译器修改函数中的代码。例如,可能会将`1+1`转换为`2`或者删除掉注释。实际的更改只会影响代码的外在形式,并且会根据所使用的JavaScript版本而变化,但并不会改变代码的语义。 116 | 117 | ## Change the mongo Shell Batch Size 修改mongo shell每次返回的结果集大小 118 | 119 | The db.collection.find()[](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) method is the JavaScript method to retrieve documents from a collection[](https://docs.mongodb.com/manual/reference/glossary/#term-collection). The db.collection.find()[](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) method returns a cursor[](https://docs.mongodb.com/manual/reference/glossary/#term-cursor) to the results; however, in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell, if the returned cursor is not assigned to a variable using the var keyword, then the cursor is automatically iterated up to 20 times to print up to the first 20 documents that match the query. The mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell will prompt Type it to iterate another 20 times. 120 | `db.collection.find()`是一个从集合中检索文档的JavaScript方法。db.collection.find()方法会返回一个游标作为结果;然而,在mongo shell中,如果返回的游标不使用var关键字分配给一个变量,则光标会自动迭代最多20次,以显示符合查询条件的前20个文档。mongo shell将提示输入`it`以再次进行20次迭代。 121 | 122 | You can set the DBQuery.shellBatchSize attribute to change the number of documents from the default value of 20, as in the following example which sets it to 10: 123 | 你可以通过设置`DBQuery.shellBatchSize`属性将文档数从默认的`20`改为`10`: 124 | 125 | ``` 126 | DBQuery.shellBatchSize = 10; 127 | ``` 128 | 129 | 130 | 131 | 原文链接:https://docs.mongodb.com/manual/tutorial/configure-mongo-shell/ 132 | 133 | 译者:金江 134 | -------------------------------------------------------------------------------- /03 The mongo Shell mongo命令行/03-03 access-the-mongo-shell-help 查看mongo shell帮助文档.md: -------------------------------------------------------------------------------- 1 | # Access the mongo Shell Help 查看mongo shell帮助文档 2 | 3 | On this page 本页内容 4 | 5 | - Command Line Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#command-line-help) 命令行帮助 6 | - Shell Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#shell-help) shell帮助 7 | - Database Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#database-help) 数据库帮助 8 | - Collection Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#collection-help) 集合帮助 9 | - Cursor Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#cursor-help) 游标帮助 10 | - Wrapper Object Help[](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#wrapper-object-help) 包装对象帮助 11 | 12 | In addition to the documentation in the MongoDB Manual[](https://docs.mongodb.com/manual/), the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell provides some additional information in its “online” help system. This document provides an overview of accessing this help information.除了MongoDB文档手册,mongo shell通过在线帮助系统提供了一些额外的信息。本文概述了如何访问这些帮助信息。 13 | 14 | ## Command Line Help 命令行帮助 15 | 16 | To see the list of options and help for starting the mongo shell, use the --help option from the command line: 通过在命令行输入--help来查看mongo shell的帮助文档 17 | ``` 18 | mongo --help 19 | ``` 20 | 21 | ## Shell Help shell帮助 22 | 23 | To see the list of help, in the mongo shell, type help: 在mongo shell中输入help查看帮助文档 24 | 25 | ``` 26 | help 27 | ``` 28 | ## Database Help 数据库帮助 29 | 30 | In the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell: 在mongo shell中 31 | 32 | * To see the list of databases on the server, use the show dbs command: [1][](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#access) 查看服务器数据库列表使用 show dbs命令 33 | 34 | ``` 35 | show dbs 36 | ``` 37 | show databases is an alias for show dbs. show databases是show dbs的别称 38 | * To see the list of help for methods you can use on the db object, call the db.help()[](https://docs.mongodb.com/manual/reference/method/db.help/#db.help) method:使用db.help()查看db对象的全部帮助方法 39 | 40 | ``` 41 | db.help() 42 | ``` 43 | 44 | * To see the implementation of a method in the shell, type the db.< method name > without the parenthesis (()), as in the following example which will return the implementation of the method db.updateUser(): 在mongo shell中使用不带括号的db.< method name >命令查看一个方法的实现,如下返回方法 db.updateUser()的实现。 45 | ``` 46 | db.updateUser 47 | ``` 48 | 49 | [1][](https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/#access) If the deployment runs with access control, the operation returns different values based on user privileges. See listDatabases Behavior[](https://docs.mongodb.com/manual/reference/command/listDatabases/#listdatabases-behavior) for details. 如果以访问控制模式运行,根据用户权限不同返回不同的值。可以到listDatabases Behavior 查看详情。 50 | 51 | ## Collection Help 集合帮助 52 | 53 | In the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell: 在mongo shell中 54 | 55 | * To see the list of collections in the current database, use the show collections command: 使用show collections查看当前数据库全部集合列表。 56 | 57 | ``` 58 | show collections 59 | ``` 60 | SEE ALSO: 也可以查看 61 | show collections[](https://docs.mongodb.com/manual/release-notes/4.0-compatibility/#compat-show-collections) 62 | 63 | * To see the help for methods available on the collection objects (e.g. db.< collection >), use the db.< collection >.help() method: 使用db.< collection >.help()查看集合可使用的帮助方法 64 | 65 | ``` 66 | db.collection.help() 67 | ``` 68 | < collection > can be the name of a collection that exists, although you may specify a collection that doesn’t exist. 集合名字可以是已存在的也可以是不存在的。 69 | 70 | * To see the collection method implementation, type the db.< collection >.< method > name without the parenthesis (()), as in the following example which will return the implementation of the save()[](https://docs.mongodb.com/manual/reference/method/db.collection.save/#db.collection.save) method: 在mongo shell中使用不带括号的db.< collection >.< method >命令查看一个集合方法的实现,如下返回 save()方法的实现。 71 | 72 | ``` 73 | db.collection.save 74 | ``` 75 | 76 | ## Cursor Help 游标帮助 77 | 78 | When you perform read operations[](https://docs.mongodb.com/manual/tutorial/query-documents/#read-operations-queries) with the find()[](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) method in the mongo shell, you can use various cursor methods to modify the find()[](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) behavior and various JavaScript methods to handle the cursor returned from the find()[](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) method. 当你在mongo shell中通过find()方法执行读操作,你可以使用各种游标方法修改find()行为,各种JavaScript方法控制游标返回的结果。 79 | 80 | * To list the available modifier and cursor handling methods, use the db.collection.find().help() command:使用 db.collection.find().help()命令列出可用的修饰符和游标处理方法: 81 | 82 | ``` 83 | db.collection.find().help() 84 | ``` 85 | < collection > can be the name of a collection that exists, although you may specify a collection that doesn’t exist.集合名字可以是已存在的也可以是不存在的。 86 | 87 | * To see the implementation of the cursor method, type the db.< collection >.find().< method > name without the parenthesis (()), as in the following example which will return the implementation of the toArray() method: 在mongo shell中使用不带括号的db.< collection >.find().< method >命令查看一个游标方法的实现,如下返回 toArray()方法的实现。 88 | 89 | ``` 90 | db.collection.find().toArray 91 | ``` 92 | 93 | Some useful methods for handling cursors are: 94 | 处理游标的一些有用方法是: 95 | 96 | * hasNext()[](https://docs.mongodb.com/manual/reference/method/cursor.hasNext/#cursor.hasNext) which checks whether the cursor has more documents to return. hasNext()检查游标是否有更多文档返回 97 | 98 | * next()[](https://docs.mongodb.com/manual/reference/method/cursor.next/#cursor.next) which returns the next document and advances the cursor position forward by one. next()返回下一个文档,并且游标前进一位。 99 | 100 | * forEach(< function >)[](https://docs.mongodb.com/manual/reference/method/cursor.forEach/#cursor.forEach) which iterates the whole cursor and applies the < function > to each document returned by the cursor. The < function > expects a single argument which corresponds to the document from each iteration. forEach(< function >)迭代所有游标并将< function >作用于每个文档。< function >需要一个参数对应于每个迭代的文档。 101 | 102 | For examples on iterating a cursor and retrieving the documents from the cursor, see cursor handling[](https://docs.mongodb.com/manual/tutorial/iterate-a-cursor/). See also Cursor[](https://docs.mongodb.com/manual/reference/method/#js-query-cursor-methods) for all available cursor methods. 可以通过cursor handling查看更多迭代游标和检索文档的示例。通过Cursor查看更多可用的游标方法。 103 | 104 | ## Wrapper Object Help 包装对象帮助 105 | 106 | To get a list of the wrapper classes available in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell, such as BinData(), type help misc in the mongo[](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell: 在mongo shell中输入BinData()或者help misc,可以得到一个可用的包装器类列表。 107 | 108 | ``` 109 | help misc 110 | ``` 111 | SEE ALSO:参见 112 | 113 | mongo Shell Methods[](https://docs.mongodb.com/manual/reference/method/)mongo shell 方法集 114 | 115 | 116 | 117 | 原文链接:https://docs.mongodb.com/manual/tutorial/access-mongo-shell-help/ 118 | 119 | 译者:金江 120 | 121 | -------------------------------------------------------------------------------- /04 MongoDB CRUD Operations MongoDB CRUD 操作/04-01 MongoDB CRUD OperationsMongoDB中的CURD操作.md: -------------------------------------------------------------------------------- 1 | # MongoDB CRUD Operations MongoDB中的CURD操作 2 | 3 | > On this page 本页面中 4 | > 5 | > - [Create Operations 创建操作](https://docs.mongodb.com/manual/crud/#create-operations) 6 | > - [Read Operations 读操作](https://docs.mongodb.com/manual/crud/#read-operations) 7 | > - [Update Operations 更新操作](https://docs.mongodb.com/manual/crud/#update-operations) 8 | > - [Delete Operations 删除操作](https://docs.mongodb.com/manual/crud/#delete-operations) 9 | > - [Bulk Write 批量写](https://docs.mongodb.com/manual/crud/#bulk-write) 10 | 11 | CRUD operations *create*, *read*, *update*, and *delete* [documents](https://docs.mongodb.com/manual/core/document/#bson-document-format).
CURD操作指的是文档的*创建*、*读*、*更新*以及*删除*操作。 12 | 13 | ## Create Operations 创建操作 14 | 15 | Create or insert operations add new [documents](https://docs.mongodb.com/manual/core/document/#bson-document-format) to a [collection](https://docs.mongodb.com/manual/core/databases-and-collections/#collections). If the collection does not currently exist, insert operations will create the collection.
创建或者插入操作将新的文档添加到一个集合中。如果集合当前并不存在,插入操作会创建该集合。 16 | 17 | MongoDB provides the following methods to insert documents into a collection:
MongoDB提供了以下两个方法来向集合中插入文档: 18 | 19 | - [`db.collection.insertOne()`](https://docs.mongodb.com/manual/reference/method/db.collection.insertOne/#db.collection.insertOne) *New in version 3.2* *3.2版本引入* 20 | - [`db.collection.insertMany()`](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/#db.collection.insertMany) *New in version 3.2* *3.2版本引入* 21 | 22 | In MongoDB, insert operations target a single [collection](https://docs.mongodb.com/manual/reference/glossary/#term-collection). All write operations in MongoDB are [atomic](https://docs.mongodb.com/manual/core/write-operations-atomicity/) on the level of a single [document](https://docs.mongodb.com/manual/core/document/).
在MongoDB中,插入操作只针对单个集合。MongoDB中的所有写操作都是单个文档级别的原子操作。 23 | 24 | ![The components of a MongoDB insertOne operations.](https://docs.mongodb.com/manual/_images/crud-annotated-mongodb-insertOne.bakedsvg.svg) 25 | 26 | For examples, see [Insert Documents](https://docs.mongodb.com/manual/tutorial/insert-documents/).
关于示例,请参考【插入文档】。 27 | 28 | ## Read Operations 读操作 29 | 30 | Read operations retrieves [documents](https://docs.mongodb.com/manual/core/document/#bson-document-format) from a [collection](https://docs.mongodb.com/manual/core/databases-and-collections/#collections); i.e. queries a collection for documents. MongoDB provides the following methods to read documents from a collection:
读操作从一个集合中检索文档;即查询集合中的文档。MongoDB提供了以下方法来从集合中读取文档: 31 | 32 | - [`db.collection.find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find) 33 | 34 | You can specify [query filters or criteria](https://docs.mongodb.com/manual/tutorial/query-documents/#read-operations-query-argument) that identify the documents to return.
你可以指定查询过滤器或条件来标识要返回的文档 35 | 36 | ![The components of a MongoDB find operation.](https://docs.mongodb.com/manual/_images/crud-annotated-mongodb-find.bakedsvg.svg) 37 | 38 | For examples, see:
更多示例,请参考: 39 | 40 | - [Query Documents 查询文档](https://docs.mongodb.com/manual/tutorial/query-documents/) 41 | - [Query on Embedded/Nested Documents 查询嵌入式文档](https://docs.mongodb.com/manual/tutorial/query-embedded-documents/) 42 | - [Query an Array 查询数据](https://docs.mongodb.com/manual/tutorial/query-arrays/) 43 | - [Query an Array of Embedded Documents 查询嵌入式文档的数组](https://docs.mongodb.com/manual/tutorial/query-array-of-documents/) 44 | 45 | ## Update Operations 更新操作 46 | 47 | Update operations modify existing [documents](https://docs.mongodb.com/manual/core/document/#bson-document-format) in a [collection](https://docs.mongodb.com/manual/core/databases-and-collections/#collections). MongoDB provides the following methods to update documents of a collection:
更新操作修改一个集合中已存在的文档。MongoDB提供了以下方法来更新一个集合中的文档: 48 | 49 | - [`db.collection.updateOne()`](https://docs.mongodb.com/manual/reference/method/db.collection.updateOne/#db.collection.updateOne) *New in version 3.2* *3.2版本引入* 50 | - [`db.collection.updateMany()`](https://docs.mongodb.com/manual/reference/method/db.collection.updateMany/#db.collection.updateMany) *New in version 3.2* *3.2版本引入* 51 | - [`db.collection.replaceOne()`](https://docs.mongodb.com/manual/reference/method/db.collection.replaceOne/#db.collection.replaceOne) *New in version 3.2* *3.2版本引入* 52 | 53 | In MongoDB, update operations target a single collection. All write operations in MongoDB are [atomic](https://docs.mongodb.com/manual/core/write-operations-atomicity/) on the level of a single document.
在MongoDB中,更新操作只针对单个集合。MongoDB中的所有写操作都是单个文档级别的原子操作。 54 | 55 | You can specify criteria, or filters, that identify the documents to update. These [filters](https://docs.mongodb.com/manual/core/document/#document-query-filter) use the same syntax as read operations.
你可以指定查询过滤器或条件来标识要更新的文档,这里的过滤器和读操作的语法是一致的。 56 | 57 | ![The components of a MongoDB updateMany operation.](https://docs.mongodb.com/manual/_images/crud-annotated-mongodb-updateMany.bakedsvg.svg) 58 | 59 | For examples, see [Update Documents](https://docs.mongodb.com/manual/tutorial/update-documents/).
关于示例,请参考【更新文档】。 60 | 61 | ## Delete Operations 删除操作 62 | 63 | Delete operations remove documents from a collection. MongoDB provides the following methods to delete documents of a collection:
删除操作从一个集合中删除文档。MongoDB提供了以下方法来从一个集合中删除文档: 64 | 65 | - [`db.collection.deleteOne()`](https://docs.mongodb.com/manual/reference/method/db.collection.deleteOne/#db.collection.deleteOne) *New in version 3.2* *3.2版本引入* 66 | - [`db.collection.deleteMany()`](https://docs.mongodb.com/manual/reference/method/db.collection.deleteMany/#db.collection.deleteMany) *New in version 3.2* *3.2版本引入* 67 | 68 | In MongoDB, delete operations target a single [collection](https://docs.mongodb.com/manual/reference/glossary/#term-collection). All write operations in MongoDB are [atomic](https://docs.mongodb.com/manual/core/write-operations-atomicity/) on the level of a single document.
在MongoDB中,删除操作只针对单个集合。MongoDB中的所有写操作都是单个文档级别的原子操作。 69 | 70 | You can specify criteria, or filters, that identify the documents to remove. These [filters](https://docs.mongodb.com/manual/core/document/#document-query-filter) use the same syntax as read operations.
你可以指定查询过滤器或条件来标识要更新的文档,这里的过滤器和读操作的语法是一致的。 71 | 72 | ![The components of a MongoDB deleteMany operation.](https://docs.mongodb.com/manual/_images/crud-annotated-mongodb-deleteMany.bakedsvg.svg) 73 | 74 | For examples, see [Delete Documents](https://docs.mongodb.com/manual/tutorial/remove-documents/).
关于示例,请参考【删除文档】。 75 | 76 | ## Bulk Write 批量写 77 | 78 | MongoDB provides the ability to perform write operations in bulk. For details, see [Bulk Write Operations](https://docs.mongodb.com/manual/core/bulk-write-operations/).
MongoDB提供了批量执行写操作的能力。更多细节请参考【批量写操作】。 79 | 80 | 81 | 82 | 原文链接:https://docs.mongodb.com/v4.2/crud/ 83 | 84 | 译者:刘翔 85 | -------------------------------------------------------------------------------- /04 MongoDB CRUD Operations MongoDB CRUD 操作/04-06 Bulk Write Operations 批量写操作.md: -------------------------------------------------------------------------------- 1 | # Bulk Write Operations 2 | 3 | # 批量写操作 4 | 5 | > On this page 本页面中 6 | > 7 | > - [Overview 总览](https://docs.mongodb.com/manual/core/bulk-write-operations/#overview) 8 | > - [Ordered vs Unordered Operations 有序 VS 无序操作](https://docs.mongodb.com/manual/core/bulk-write-operations/#ordered-vs-unordered-operations) 9 | > - [bulkWrite() Methods bulkWrite()方法](https://docs.mongodb.com/manual/core/bulk-write-operations/#bulkwrite-methods) 10 | > - [Strategies for Bulk Inserts to a Sharded Collection 分片集合的批量插入策略](https://docs.mongodb.com/manual/core/bulk-write-operations/#strategies-for-bulk-inserts-to-a-sharded-collection) 11 | 12 | ## Overview 13 | 14 | MongoDB provides clients the ability to perform write operations in bulk. Bulk write operations affect a *single* collection. MongoDB allows applications to determine the acceptable level of acknowledgement required for bulk write operations.
MongoDB使客户端能够批量执行写操作。 批量写入操作会影响*单个*集合。 MongoDB允许应用程序确定批量写入操作所需的可接受的确认级别。 15 | 16 | *New in version 3.2. 3.2版本新增* 17 | 18 | The [`db.collection.bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) method provides the ability to perform bulk insert, update, and remove operations. MongoDB also supports bulk insert through the [`db.collection.insertMany()`](https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/#db.collection.insertMany).
`db.collection.bulkWrite()`方法提供了执行批量插入,更新和删除操作的能力。对于批量插入而言,MongoDB也支持`db.collection.insertMany()`。 19 | 20 | ## Ordered vs Unordered Operations 有序 VS 无序操作 21 | 22 | Bulk write operations can be either *ordered* or *unordered*.
批量写操作可以是*有序的*,也可以*无序的*。 23 | 24 | With an ordered list of operations, MongoDB executes the operations serially. If an error occurs during the processing of one of the write operations, MongoDB will return without processing any remaining write operations in the list. See [ordered Bulk Write](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-example-bulk-write-operation)
使用操作的有序列表,MongoDB串行地执行操作。 如果在某个单独的写操作的处理过程中发生错误,MongoDB将直接返回而不再继续处理列表中任何剩余的写操作。 请参考【有序的批量写入】 25 | 26 | With an unordered list of operations, MongoDB can execute the operations in parallel, but this behavior is not guaranteed. If an error occurs during the processing of one of the write operations, MongoDB will continue to process remaining write operations in the list. See [Unordered Bulk Write](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-example-unordered-bulk-write).
使用无序的操作列表,MongoDB可以并行地执行操作,但是不能保证此行为。 如果某个单独的写操作的处理过程中发生错误,MongoDB将继续处理列表中剩余的写操作。 请参考【无序的批量写入】。 27 | 28 | Executing an ordered list of operations on a sharded collection will generally be slower than executing an unordered list since with an ordered list, each operation must wait for the previous operation to finish.
在分片集合上执行有序的批量写操作通常比执行无序批量写操作要慢。这是因为对于有序列表而言,每个操作都必须等待上一个操作完成后才能执行。 29 | 30 | By default, [`bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) performs `ordered` operations. To specify `unordered` write operations, set `ordered: false` in the options document. 31 | 32 | 默认情况下,`bulkWrite()`执行**有序的**写入。 要指定**无序的**写入,请在选项文档中设置`ordered:false`。 33 | 34 | See [Execution of Operations](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-executionofoperations)
请参考【操作的执行】 35 | 36 | ## bulkWrite() Methods bulkWrite()方法 37 | 38 | [`bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) supports the following write operations:
`bulkWrite()`支持如下操作: 39 | 40 | - [insertOne](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-insertone) 41 | - [updateOne](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-updateonemany) 42 | - [updateMany](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-updateonemany) 43 | - [replaceOne](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-replaceone) 44 | - [deleteOne](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-deleteonemany) 45 | - [deleteMany](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-write-operations-deleteonemany) 46 | 47 | Each write operation is passed to [`bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) as a document in an array.
每个写操作都以数组中的文档形式被传递给`bulkWrite()` 48 | 49 | For example, the following performs multiple write operations:
比如说,要执行下面这一系列写操作: 50 | 51 | The `characters` collection contains the following documents:
`characters`集合包含以下文档: 52 | 53 | ```json 54 | { "_id" : 1, "char" : "Brisbane", "class" : "monk", "lvl" : 4 }, 55 | { "_id" : 2, "char" : "Eldon", "class" : "alchemist", "lvl" : 3 }, 56 | { "_id" : 3, "char" : "Meldane", "class" : "ranger", "lvl" : 3 } 57 | ``` 58 | 59 | The following [`bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) performs multiple operations on the collection:
接下来的`bulkWrite()`将在此集合上执行批量写入的操作。 60 | 61 | ```json 62 | try { 63 | db.characters.bulkWrite( 64 | [ 65 | { insertOne : 66 | { 67 | "document" : 68 | { 69 | "_id" : 4, "char" : "Dithras", "class" : "barbarian", "lvl" : 4 70 | } 71 | } 72 | }, 73 | { insertOne : 74 | { 75 | "document" : 76 | { 77 | "_id" : 5, "char" : "Taeln", "class" : "fighter", "lvl" : 3 78 | } 79 | } 80 | }, 81 | { updateOne : 82 | { 83 | "filter" : { "char" : "Eldon" }, 84 | "update" : { $set : { "status" : "Critical Injury" } } 85 | } 86 | }, 87 | { deleteOne : 88 | { "filter" : { "char" : "Brisbane"} } 89 | }, 90 | { replaceOne : 91 | { 92 | "filter" : { "char" : "Meldane" }, 93 | "replacement" : { "char" : "Tanys", "class" : "oracle", "lvl" : 4 } 94 | } 95 | } 96 | ] 97 | ); 98 | } 99 | catch (e) { 100 | print(e); 101 | } 102 | ``` 103 | 104 | The operation returns the following:
该操作将返回如下的结果: 105 | 106 | ```json 107 | { 108 | "acknowledged" : true, 109 | "deletedCount" : 1, 110 | "insertedCount" : 2, 111 | "matchedCount" : 2, 112 | "upsertedCount" : 0, 113 | "insertedIds" : { 114 | "0" : 4, 115 | "1" : 5 116 | }, 117 | "upsertedIds" : { 118 | 119 | } 120 | } 121 | ``` 122 | 123 | For more examples, see [bulkWrite() Examples](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#bulkwrite-example-bulk-write-operation)
想了解更多例子,请参考【`bulkWrite()` 示例】 124 | 125 | ## Strategies for Bulk Inserts to a Sharded Collection 分片集合的批量插入策略 126 | 127 | Large bulk insert operations, including initial data inserts or routine data import, can affect [sharded cluster](https://docs.mongodb.com/manual/reference/glossary/#term-sharded-cluster)performance. For bulk inserts, consider the following strategies:
大量的插入操作(包括初始数据插入或者定时的数据导入)可能会影响分片集群的性能。对于批量插入,请考虑以下策略: 128 | 129 | ### Pre-Split the Collection 对分片集合进行预拆分 130 | 131 | If the sharded collection is empty, then the collection has only one initial [chunk](https://docs.mongodb.com/manual/reference/glossary/#term-chunk), which resides on a single shard. MongoDB must then take time to receive data, create splits, and distribute the split chunks to the available shards. To avoid this performance cost, you can pre-split the collection, as described in [Split Chunks in a Sharded Cluster](https://docs.mongodb.com/manual/tutorial/split-chunks-in-sharded-cluster/).
如果分片集合为空,则该集合只有一个存储在单个分片上的初始数据块,MongoDB必须花一些时间来接收数据,创建拆分并将拆分的块分发到其他分片上。为了避免这种性能开销,您可以对分片集合进行预拆分,请参考【分片集群中的数据块拆分】中的描述。 132 | 133 | ### Unordered Writes to `mongos` 对mongos的无序写入 134 | 135 | To improve write performance to sharded clusters, use [`bulkWrite()`](https://docs.mongodb.com/manual/reference/method/db.collection.bulkWrite/#db.collection.bulkWrite) with the optional parameter `ordered` set to `false`. [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) can attempt to send the writes to multiple shards simultaneously. For *empty* collections, first pre-split the collection as described in [Split Chunks in a Sharded Cluster](https://docs.mongodb.com/manual/tutorial/split-chunks-in-sharded-cluster/).
136 | 137 | 要提高对分片集群的写入性能,请使用带有可选参数`ordered:false`的`bulkWrite()`方法。mongos会尝试同时将写入发送到多个分片。对于空集合,请首先按照【在分片集群中拆分数据块】中描述的进行集合的预拆分。 138 | 139 | ### Avoid Monotonic Throttling 避免单调插入带来的瓶颈 140 | 141 | If your shard key increases monotonically during an insert, then all inserted data goes to the last chunk in the collection, which will always end up on a single shard. Therefore, the insert capacity of the cluster will never exceed the insert capacity of that single shard.
如果您的分片键在插入过程中是单调增加的,那么所有插入的数据都会插入到该分片集合的最后一个数据块中,也就是说会落到某单个分片上。因此,集群的插入能力将永远不会超过该单个分片的插入性能(木桶的短板原理)。 142 | 143 | If your insert volume is larger than what a single shard can process, and if you cannot avoid a monotonically increasing shard key, then consider the following modifications to your application:
如果插入量大于单个分片可以处理的数据量,并且无法避免单调增加的分片键,那么可以考虑对应用程序进行如下修改: 144 | 145 | - Reverse the binary bits of the shard key. This preserves the information and avoids correlating insertion order with increasing sequence of values.
翻转分片键的二进制位。这样可以保留信息的同时避免插入顺序与递增插入值之间的关联性。 146 | - Swap the first and last 16-bit words to “shuffle” the inserts.
交换第一个和最后16比特来实现“随机”插入。 147 | 148 | EXAMPLE 示例 149 | 150 | The following example, in C++, swaps the leading and trailing 16-bit word of [BSON](https://docs.mongodb.com/manual/reference/glossary/#term-bson) [ObjectIds](https://docs.mongodb.com/manual/reference/glossary/#term-objectid) generated so they are no longer monotonically increasing.
下面的C++例子中,交换了生成BSON 对象id(`ObjectIds`)的前16和末尾16比特值,因此它不再是单调递增的。 151 | 152 | 153 | 154 | ```json 155 | using namespace mongo; 156 | OID make_an_id() { 157 | OID x = OID::gen(); 158 | const unsigned char *p = x.getData(); 159 | swap( (unsigned short&) p[0], (unsigned short&) p[10] ); 160 | return x; 161 | } 162 | 163 | void foo() { 164 | // create an object 165 | BSONObj o = BSON( "_id" << make_an_id() << "x" << 3 << "name" << "jane" ); 166 | // now we may insert o into a sharded collection 167 | } 168 | ``` 169 | 170 | SEE ALSO 另请参考 171 | 172 | [Shard Keys](https://docs.mongodb.com/manual/core/sharding-shard-key/#sharding-shard-key) for information on choosing a sharded key. Also see [Shard Key Internals](https://docs.mongodb.com/manual/core/sharding-shard-key/#sharding-internals-shard-keys) (in particular, [Choosing a Shard Key](https://docs.mongodb.com/manual/core/sharding-shard-key/#sharding-internals-operations-and-reliability)).
173 | 174 | 【分片键】来获得如何选择分片键的相关信息。另请参考【分片键】(尤其是其中【选择一个分片键】的相关章节) 175 | 176 | 原文链接:https://docs.mongodb.com/manual/core/bulk-write-operations/ 177 | 178 | 译者:刘翔 179 | -------------------------------------------------------------------------------- /04 MongoDB CRUD Operations MongoDB CRUD 操作/04-13 MongoDB CRUD Concepts MongoDB 增删改查 概念.md: -------------------------------------------------------------------------------- 1 | # MongoDB CRUD Concepts 2 | 3 | # MongoDB 增删改查 概念 4 | 5 | This section contains information on additional concepts related to CRUD operations in MongoDB. 6 | 7 | 本部分包含有关与MongoDB中的CRUD操作相关的其他概念的信息。 8 | 9 | Atomicity, consistency, and distributed operations 10 | 11 | 原子性,一致性和分布式操作 12 | 13 | - [Atomicity and Transactions](https://docs.mongodb.com/manual/core/write-operations-atomicity/) 14 | - [Read Isolation, Consistency, and Recency](https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/) 15 | - [Distributed Queries](https://docs.mongodb.com/manual/core/distributed-queries/) 16 | - [Linearizable Reads via findAndModify](https://docs.mongodb.com/manual/tutorial/perform-findAndModify-linearizable-reads/) 17 | - [原子性和事务](https://docs.mongodb.com/manual/core/write-operations-atomicity/) 18 | - [读隔离性, 一致性, 和新近度](https://docs.mongodb.com/manual/core/read-isolation-consistency-recency/) 19 | - [分布式查询](https://docs.mongodb.com/manual/core/distributed-queries/) 20 | - [通过查找修改进行线性读](https://docs.mongodb.com/manual/tutorial/perform-findAndModify-linearizable-reads/) 21 | 22 | Query Plan, Performance, and Analysis 23 | 24 | 查询计划,性能和分析 25 | 26 | - [Query Plans](https://docs.mongodb.com/manual/core/query-plans/) 27 | - [Query Optimization](https://docs.mongodb.com/manual/core/query-optimization/) 28 | - [Analyze Query Performance](https://docs.mongodb.com/manual/tutorial/analyze-query-plan/) 29 | - [Write Operation Performance](https://docs.mongodb.com/manual/core/write-performance/) 30 | - [查询计划](https://docs.mongodb.com/manual/core/query-plans/) 31 | - [查询优化](https://docs.mongodb.com/manual/core/query-optimization/) 32 | - [分析查询性能](https://docs.mongodb.com/manual/tutorial/analyze-query-plan/) 33 | - [写操作性能](https://docs.mongodb.com/manual/core/write-performance/) 34 | 35 | Miscellaneous 36 | 37 | 其他 38 | 39 | [Tailable Cursors](https://docs.mongodb.com/manual/core/tailable-cursors/) 40 | 41 | [尾标](https://docs.mongodb.com/manual/core/tailable-cursors/) 42 | 43 | SEE ALSO 44 | 45 | 也可以看 46 | 47 | [Transactions](https://docs.mongodb.com/manual/core/transactions/) 48 | 49 | [事务](https://docs.mongodb.com/manual/core/transactions/) 50 | -------------------------------------------------------------------------------- /08 Indexes 索引/08-02 Single Field Indexes单字段索引.md: -------------------------------------------------------------------------------- 1 | # Single Field Indexes 单字段索引 2 | 3 | 4 | 5 | On this page 6 | 7 | - [Create an Ascending Index on a Single Field](https://docs.mongodb.com/manual/core/index-single/#create-an-ascending-index-on-a-single-field) 8 | - [Create an Index on an Embedded Field](https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-an-embedded-field) 9 | - [Create an Index on Embedded Document](https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-embedded-document) 10 | - [Additional Considerations](https://docs.mongodb.com/manual/core/index-single/#additional-considerations) 11 | 12 | 在本页面 13 | 14 | - [在单个字段上创建升序索引](https://docs.mongodb.com/manual/core/index-single/#create-an-ascending-index-on-a-single-field) 15 | - [在嵌入式字段上创建索引](https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-an-embedded-field) 16 | - [在嵌入式文档上创建索引](https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-embedded-document) 17 | - [其他注意事项](https://docs.mongodb.com/manual/core/index-single/#additional-considerations) 18 | 19 | 20 | 21 | MongoDB provides complete support for indexes on any field in a [collection](https://docs.mongodb.com/manual/reference/glossary/#term-collection) of [documents](https://docs.mongodb.com/manual/reference/glossary/#term-document). By default, all collections have an index on the [_id field](https://docs.mongodb.com/manual/indexes/#index-type-id), and applications and users may add additional indexes to support important queries and operations. 22 | 23 | MongoDB为[文档](https://docs.mongodb.com/manual/reference/glossary/#term-document)[集合](https://docs.mongodb.com/manual/reference/glossary/#term-collection)中任何字段提供完整的索引支持 。默认情况下,所有集合在[_id字段](https://docs.mongodb.com/manual/indexes/#index-type-id)上都有索引,应用程序和用户可以添加其他索引来支持重要的查询和操作。 24 | 25 | This document describes ascending/descending indexes on a single field. 26 | 27 | 本文档描述了在单个字段上升序/降序索引。 28 | 29 | ![Diagram of an index on the ``score`` field (ascending).](https://docs.mongodb.com/manual/_images/index-ascending.bakedsvg.svg) 30 | 31 | ## Create an Ascending Index on a Single Field 32 | 33 | ## 在单个字段上创建升序索引[¶](https://docs.mongodb.com/manual/core/index-single/#create-an-ascending-index-on-a-single-field) 34 | 35 | Consider a collection named `records` that holds documents that resemble the following sample document: 36 | 37 | `records`集合,它包含文档如下: 38 | 39 | copy 复制 40 | 41 | ``` 42 | { 43 | "_id": ObjectId("570c04a4ad233577f97dc459"), 44 | "score": 1034, 45 | "location": { state: "NY", city: "New York" } 46 | } 47 | ``` 48 | 49 | The following operation creates an ascending index on the `score` field of the `records` collection: 50 | 51 | 以下操作在`records`集合的`score` 字段上创建升序索引: 52 | 53 | copy 复制 54 | 55 | ``` 56 | db.records.createIndex( { score: 1 } ) 57 | ``` 58 | 59 | The value of the field in the index specification describes the kind of index for that field. For example, a value of `1` specifies an index that orders items in ascending order. A value of `-1` specifies an index that orders items in descending order. For additional index types, see [index types](https://docs.mongodb.com/manual/indexes/#index-types). 60 | 61 | 索引规范中字段的值描述了该字段的索引类型。例如,值`1`表示以升序对项目进行排序的索引。值`-1`指定按降序对项目进行排序的索引。有关其他索引类型,请参见[索引类型](https://docs.mongodb.com/manual/indexes/#index-types)。 62 | 63 | The created index will support queries that select on the field `score`, such as the following: 64 | 65 | 创建的索引将支持在 `score`字段上选择的查询,例如: 66 | 67 | copy 复制 68 | 69 | ``` 70 | db.records.find( { score: 2 } ) 71 | db.records.find( { score: { $gt: 10 } } ) 72 | ``` 73 | 74 | 75 | 76 | ## Create an Index on an Embedded Field在嵌入式字段上创建索引 77 | 78 | You can create indexes on fields within embedded documents, just as you can index top-level fields in documents. Indexes on embedded fields differ from [indexes on embedded documents](https://docs.mongodb.com/manual/core/index-single/#index-embedded-documents), which include the full content up to the maximum `index size` of the embedded document in the index. Instead, indexes on embedded fields allow you to use a “dot notation,” to introspect into embedded documents. 79 | 80 | 您可以在嵌入式文档中的字段上创建索引,就像可以在文档中索引顶级字段一样。嵌入字段上的[索引与嵌入文档上的索引](https://docs.mongodb.com/manual/core/index-single/#index-embedded-documents)不同,后者包含完整内容,直到[索引中嵌入文档](https://docs.mongodb.com/manual/core/index-single/#index-embedded-documents)的最大值。相反,嵌入式字段上的索引允许使用“点符号”来表示嵌入式文档。 81 | 82 | Consider a collection named `records` that holds documents that resemble the following sample document: 83 | 84 | `records`集合,它包含文档如下: 85 | 86 | copy 复制 87 | 88 | ``` 89 | { 90 | "_id": ObjectId("570c04a4ad233577f97dc459"), 91 | "score": 1034, 92 | "location": { state: "NY", city: "New York" } 93 | } 94 | ``` 95 | 96 | The following operation creates an index on the `location.state` field: 97 | 98 | 以下操作在`location.state` 字段上创建索引: 99 | 100 | copy 复制 101 | 102 | ``` 103 | db.records.createIndex( { "location.state": 1 } ) 104 | ``` 105 | 106 | The created index will support queries that select on the field `location.state`, such as the following: 107 | 108 | 创建的索引将支持在字段上选择的查询 `location.state`,例如: 109 | 110 | copy 复制 111 | 112 | ``` 113 | db.records.find( { "location.state": "CA" } ) 114 | db.records.find( { "location.city": "Albany", "location.state": "NY" } ) 115 | ``` 116 | 117 | ## Create an Index on Embedded Document在嵌入式文档上创建索引[¶](https://docs.mongodb.com/manual/core/index-single/#create-an-index-on-embedded-document) 118 | 119 | You can also create indexes on embedded document as a whole.您还可以在整个嵌入式文档上创建索引。 120 | 121 | Consider a collection named `records` that holds documents that resemble the following sample document: 122 | 123 | `records`集合,它包含文档如下: 124 | 125 | copy 复制 126 | 127 | ``` 128 | { 129 | "_id": ObjectId("570c04a4ad233577f97dc459"), 130 | "score": 1034, 131 | "location": { state: "NY", city: "New York" } 132 | } 133 | ``` 134 | 135 | The `location` field is an embedded document, containing the embedded fields `city` and `state`. The following command creates an index on the `location` field as a whole: 136 | 137 | 该`location`字段是一个嵌入式文档,包含嵌入式字段 `city`和`state`。以下命令在整个`location` 字段上创建索引: 138 | 139 | copy 复制 140 | 141 | ``` 142 | db.records.createIndex( { location: 1 } ) 143 | ``` 144 | 145 | The following query can use the index on the `location` field: 146 | 147 | 以下查询可以使用`location`字段上的索引: 148 | 149 | copy 复制 150 | 151 | ``` 152 | db.records.find( { location: { city: "New York", state: "NY" } } ) 153 | ``` 154 | 155 | NOTE 156 | 157 | Although the query can use the index, the result set does not include the sample document above. When performing equality matches on embedded documents, field order matters and the embedded documents must match exactly. See [Query Embedded Documents](https://docs.mongodb.com/manual/reference/method/db.collection.find/#query-embedded-documents) for more information regarding querying on embedded documents. 158 | 159 | 注意 160 | 161 | 尽管查询可以使用索引,但是结果集不包括上面的示例文档。在嵌入式文档执行等值匹配时,字段顺序事项和嵌入式文档必须完全匹配。有关[查询嵌入式文档](https://docs.mongodb.com/manual/reference/method/db.collection.find/#query-embedded-documents)的更多信息,请参见[查询嵌入式](https://docs.mongodb.com/manual/reference/method/db.collection.find/#query-embedded-documents)文档。 162 | 163 | 164 | 165 | ## Additional Considerations其他注意事项[¶](https://docs.mongodb.com/manual/core/index-single/#additional-considerations) 166 | 167 | Applications may encounter reduced performance during index builds, including limited read/write access to the collection. For more information on the index build process, see [Index Builds on Populated Collections](https://docs.mongodb.com/manual/core/index-creation/#index-operations), including the [Index Builds in Replicated Environments](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build) section. 168 | 169 | 应用程序在建立索引期间可能会遇到性能下降的情况,包括对集合的有限读/写访问权限。有关索引构建过程的更多信息,请参见 [“填充集合上](https://docs.mongodb.com/manual/core/index-creation/#index-operations)的[索引构建”](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build),包括“ [复制环境中](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build)的 [索引构建”](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build)部分。 170 | 171 | Some drivers may specify indexes, using `NumberLong(1)` rather than `1` as the specification. This does not have any affect on the resulting index. 172 | 173 | 一些驱动程序可能使用`NumberLong(1)`而不是 `1`将规范指定为索引。这对结果索引没有任何影响。 174 | 175 | 176 | 177 | 原文链接:https://docs.mongodb.com/manual/core/index-single/ 178 | 179 | 译者:莫薇 180 | 181 | update:小芒果 -------------------------------------------------------------------------------- /08 Indexes 索引/08-03 Compound Indexes复合索引.md: -------------------------------------------------------------------------------- 1 | # Compound Indexes 2 | 3 | # 复合索引[¶](https://docs.mongodb.com/manual/core/index-compound/#compound-indexes) 4 | 5 | On this page 6 | 7 | - [Create a Compound Index](https://docs.mongodb.com/manual/core/index-compound/#create-a-compound-index) 8 | - [Sort Order](https://docs.mongodb.com/manual/core/index-compound/#sort-order) 9 | - [Prefixes](https://docs.mongodb.com/manual/core/index-compound/#prefixes) 10 | - [Index Intersection](https://docs.mongodb.com/manual/core/index-compound/#index-intersection) 11 | - [Additional Considerations](https://docs.mongodb.com/manual/core/index-compound/#additional-considerations) 12 | 13 | 在本页面 14 | 15 | - [创建复合索引](https://docs.mongodb.com/manual/core/index-compound/#create-a-compound-index) 16 | - [排序顺序](https://docs.mongodb.com/manual/core/index-compound/#sort-order) 17 | - [前缀](https://docs.mongodb.com/manual/core/index-compound/#prefixes) 18 | - [索引交集](https://docs.mongodb.com/manual/core/index-compound/#index-intersection) 19 | - [其他注意事项](https://docs.mongodb.com/manual/core/index-compound/#additional-considerations) 20 | 21 | MongoDB supports *compound indexes*, where a single index structure holds references to multiple fields [[1\]](https://docs.mongodb.com/manual/core/index-compound/#compound-index-field-limit) within a collection’s documents. The following diagram illustrates an example of a compound index on two fields: 22 | 23 | MongoDB支持*复合索引*,其中单个索引对集合文档中多个字段[[1\]的](https://docs.mongodb.com/manual/core/index-compound/#compound-index-field-limit)引用。下图说明了两个字段上的复合索引示例: 24 | 25 | ![Diagram of a compound index on the ``userid`` field (ascending) and the ``score`` field (descending). The index sorts first by the ``userid`` field and then by the ``score`` field.](https://docs.mongodb.com/manual/_images/index-compound-key.bakedsvg.svg) 26 | 27 | | [[1\]](https://docs.mongodb.com/manual/core/index-compound/#id1) | MongoDB imposes a [`limit of 32 fields for any compound index`](https://docs.mongodb.com/manual/reference/limits/#Number-of-Indexed-Fields-in-a-Compound-Index). | 28 | | ------------------------------------------------------------ | ------------------------------------------------------------ | 29 | | | | 30 | 31 | 32 | 33 | | [[1\]](https://docs.mongodb.com/manual/core/index-compound/#id1) | 对于复合索引最多支持32个字段。 | 34 | | ------------------------------------------------------------ | ------------------------------ | 35 | | | | 36 | 37 | Compound indexes can support queries that match on multiple fields. 38 | 39 | 复合索引可以支持在多个字段上匹配的查询。 40 | 41 | 42 | 43 | ## Create a Compound Index 创建复合索引 44 | 45 | To create a [compound index](https://docs.mongodb.com/manual/core/index-compound/#index-type-compound) use an operation that resembles the following prototype: 46 | 47 | 创建[复合索引,](https://docs.mongodb.com/manual/core/index-compound/#index-type-compound)使用如下操作: 48 | 49 | copy 复制 50 | 51 | ``` 52 | db.collection.createIndex( { : , : , ... } ) 53 | ``` 54 | 55 | The value of the field in the index specification describes the kind of index for that field. For example, a value of `1` specifies an index that orders items in ascending order. A value of `-1` specifies an index that orders items in descending order. For additional index types, see [index types](https://docs.mongodb.com/manual/indexes/#index-types). 56 | 57 | 索引规范中字段的值描述了该字段的索引类型。例如,值`1`表示以升序对项目进行排序的索引。值`-1`指定按降序对项目进行排序的索引。有关其他索引类型,请参见[索引类型](https://docs.mongodb.com/manual/indexes/#index-types)。 58 | 59 | IMPORTANT 60 | 61 | You may not create compound indexes that have `hashed` index type. You will receive an error if you attempt to create a compound index that includes [a hashed index field](https://docs.mongodb.com/manual/core/index-hashed/). 62 | 63 | 重要 64 | 65 | 您无法创建具有`hashed`索引类型的复合索引 。如果尝试创建包含[哈希索引字段](https://docs.mongodb.com/manual/core/index-hashed/)的复合索引,则会收到错误消息。 66 | 67 | Consider a collection named `products` that holds documents that resemble the following document: 68 | 69 | 如:`products`集合,包含如下文档: 70 | 71 | copy 复制 72 | 73 | ``` 74 | { 75 | "_id": ObjectId(...), 76 | "item": "Banana", 77 | "category": ["food", "produce", "grocery"], 78 | "location": "4th Street Store", 79 | "stock": 4, 80 | "type": "cases" 81 | } 82 | ``` 83 | 84 | The following operation creates an ascending index on the `item` and `stock` fields: 85 | 86 | 以下操作在`item`和 `stock`字段上创建一个升序索引: 87 | 88 | copy 复制 89 | 90 | ``` 91 | db.products.createIndex( { "item": 1, "stock": 1 } ) 92 | ``` 93 | 94 | The order of the fields listed in a compound index is important. The index will contain references to documents sorted first by the values of the `item` field and, within each value of the `item` field, sorted by values of the stock field. See [Sort Order](https://docs.mongodb.com/manual/core/index-compound/#index-ascending-and-descending) for more information. 95 | 96 | 复合索引中列出的字段的顺序很重要。索引将包含对文档的引用,这些文档首先按`item`字段的值排序,然后在该`item`字段的每个值按stock字段值进行排序。有关更多信息,请参见[排序顺序](https://docs.mongodb.com/manual/core/index-compound/#index-ascending-and-descending)。 97 | 98 | In addition to supporting queries that match on all the index fields, compound indexes can support queries that match on the prefix of the index fields. That is, the index supports queries on the `item` field as well as both `item` and `stock` fields: 99 | 100 | 除了支持在所有索引字段上匹配的查询之外,复合索引还可以支持在索引字段的前缀上匹配的查询。也就是说,索引支持对`item`和`stock`字段的查询: 101 | 102 | copy 复制 103 | 104 | ``` 105 | db.products.find( { item: "Banana" } ) 106 | db.products.find( { item: "Banana", stock: { $gt: 5 } } ) 107 | ``` 108 | 109 | For details, see [Prefixes](https://docs.mongodb.com/manual/core/index-compound/#compound-index-prefix). 110 | 111 | 有关详细信息,请参见[前缀](https://docs.mongodb.com/manual/core/index-compound/#compound-index-prefix)。 112 | 113 | ## Sort Order排序顺序[¶](https://docs.mongodb.com/manual/core/index-compound/#sort-order) 114 | 115 | Indexes store references to fields in either ascending (`1`) or descending (`-1`) sort order. For single-field indexes, the sort order of keys doesn’t matter because MongoDB can traverse the index in either direction. However, for [compound indexes](https://docs.mongodb.com/manual/core/index-compound/#index-type-compound), sort order can matter in determining whether the index can support a sort operation. 116 | 117 | 索引以升序(`1`)或降序(`-1`)排序顺序存储对字段的引用。对于单字段索引,键的排序顺序无关紧要,因为MongoDB可以在任一方向上遍历索引。但是,对于[复合索引](https://docs.mongodb.com/manual/core/index-compound/#index-type-compound),排序顺序决定索引是否支持排序操作。 118 | 119 | Consider a collection `events` that contains documents with the fields `username` and `date`. Applications can issue queries that return results sorted first by ascending `username` values and then by descending (i.e. more recent to last) `date` values, such as: 120 | 121 | `events`集合包含字段`username`和`date`。应用程序可以发出返回结果的查询,这些查询首先是按升序`username`排序,然后按降序(即从最新到最后)`date`值排序,例如: 122 | 123 | copy 复制 124 | 125 | ``` 126 | db.events.find().sort( { username: 1, date: -1 } ) 127 | ``` 128 | 129 | or queries that return results sorted first by descending `username` values and then by ascending `date` values, such as: 130 | 131 | 或返回结果的查询首先按降序`username`值排列 ,然后按升序`date`值排列,例如: 132 | 133 | copy 复制 134 | 135 | ``` 136 | db.events.find().sort( { username: -1, date: 1 } ) 137 | ``` 138 | 139 | The following index can support both these sort operations: 140 | 141 | 以下索引可以支持这两种排序操作: 142 | 143 | copy 复制 144 | 145 | ``` 146 | db.events.createIndex( { "username" : 1, "date" : -1 } ) 147 | ``` 148 | 149 | However, the above index **cannot** support sorting by ascending `username` values and then by ascending `date` values, such as the following: 150 | 151 | 但是,上面的索引不支持按升序`username`值排序,然后按升序 `date`值排序,如下所示: 152 | 153 | copy 复制 154 | 155 | ``` 156 | db.events.find().sort( { username: 1, date: 1 } ) 157 | ``` 158 | 159 | For more information on sort order and compound indexes, see [Use Indexes to Sort Query Results](https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/). 160 | 161 | 有关排序顺序和复合索引的更多信息,请参见 [使用索引对查询结果进行排序](https://docs.mongodb.com/manual/tutorial/sort-results-with-indexes/)。 162 | 163 | 164 | 165 | ## Prefixes前缀[¶](https://docs.mongodb.com/manual/core/index-compound/#prefixes) 166 | 167 | Index prefixes are the *beginning* subsets of indexed fields. For example, consider the following compound index: 168 | 169 | 索引前缀是索引字段的*beginning*子集。例如,复合索引: 170 | 171 | copy 复制 172 | 173 | ``` 174 | { "item": 1, "location": 1, "stock": 1 } 175 | ``` 176 | 177 | The index has the following index prefixes: 178 | 179 | 索引具有以下索引前缀: 180 | 181 | - `{ item: 1 }` 182 | - `{ item: 1, location: 1 }` 183 | 184 | For a compound index, MongoDB can use the index to support queries on the index prefixes. As such, MongoDB can use the index for queries on the following fields: 185 | 186 | 对于复合索引,MongoDB可以使用索引来支持对索引前缀的查询。这样,MongoDB可以将索引用于以下字段的查询: 187 | 188 | - the `item` field, 189 | - the `item` field *and* the `location` field, 190 | - the `item` field *and* the `location` field *and* the `stock` field. 191 | 192 | 193 | 194 | - `item` 字段, 195 | - `item` 字段和`location`字段, 196 | - `item` 字段,`location`字段和`stock` 字段。 197 | 198 | 199 | 200 | MongoDB can also use the index to support a query on `item` and `stock` fields since `item` field corresponds to a prefix. However, the index would not be as efficient in supporting the query as would be an index on only `item` and `stock`. 201 | 202 | MongoDB索引支持对`item`和 `stock`字段的查询,因为`item`字段对应于前缀。但是,索引在支持查询方面的效率不如仅索引`item`和`stock`。 203 | 204 | However, MongoDB cannot use the index to support queries that include the following fields since without the `item` field, none of the listed fields correspond to a prefix index: 205 | 206 | 但是,MongoDB无法使用索引来支持包含如下查询,因为没有`item`字段,所列出的字段无法使用前缀索引: 207 | 208 | - the `location` field, 209 | - the `stock` field, or 210 | - the `location` and `stock` fields. 211 | 212 | 213 | 214 | - `location` 字段, 215 | - `stock` 字段, 216 | - `location` 和 `stock`字段。 217 | 218 | 219 | 220 | If you have a collection that has both a compound index and an index on its prefix (e.g. `{ a: 1, b: 1 }` and `{ a: 1 }`), if neither index has a sparse or unique constraint, then you can remove the index on the prefix (e.g. `{ a: 1 }`). MongoDB will use the compound index in all of the situations that it would have used the prefix index. 221 | 222 | 如果您的集合同时具有复合索引`{ a: 1, b: 1 }`和前缀索引`{ a: 1 }`,且两个索引都没有稀疏或唯一约束,则可以删除前缀上的索引`{ a: 1 }`。MongoDB在所有使用前缀索引的情况下都将使用复合索引。 223 | 224 | 225 | 226 | ## Index Intersection索引交集 227 | 228 | Starting in version 2.6, MongoDB can use [index intersection](https://docs.mongodb.com/manual/core/index-intersection/) to fulfill queries. The choice between creating compound indexes that support your queries or relying on index intersection depends on the specifics of your system. See [Index Intersection and Compound Indexes](https://docs.mongodb.com/manual/core/index-intersection/#index-intersection-compound-indexes) for more details. 229 | 230 | 从2.6版开始,MongoDB可以使用[索引交集](https://docs.mongodb.com/manual/core/index-intersection/)来完成查询。创建支持查询的复合索引还是依赖索引交集取决于系统的具体情况。更多详细信息,请参见 [索引交集和复合索引](https://docs.mongodb.com/manual/core/index-intersection/#index-intersection-compound-indexes)。 231 | 232 | 233 | 234 | ## Additional Considerations其他注意事项 235 | 236 | Applications may encounter reduced performance during index builds, including limited read/write access to the collection. For more information on the index build process, see [Index Builds on Populated Collections](https://docs.mongodb.com/manual/core/index-creation/#index-operations), including the [Index Builds in Replicated Environments](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build) section. 237 | 238 | 应用程序在建立索引期间可能会遇到性能下降的情况,包括对集合的有限读/写访问权限。有关索引构建过程的更多信息,请参见 [“填充集合上](https://docs.mongodb.com/manual/core/index-creation/#index-operations)的[索引构建”](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build),包括“ [复制环境中](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build)的 [索引构建”](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build)部分。 239 | 240 | Some drivers may specify indexes, using `NumberLong(1)` rather than `1` as the specification. This does not have any affect on the resulting index. 241 | 242 | 一些驱动程序可能使用`NumberLong(1)`而不是 `1`将规范指定为索引。这对结果索引没有任何影响。 243 | 244 | 245 | 246 | 原文链接:https://docs.mongodb.com/manual/core/index-compound/ 247 | 248 | 译者:莫薇 249 | 250 | update:小芒果 -------------------------------------------------------------------------------- /08 Indexes 索引/08-10 Hashed Indexes 哈希索引.md: -------------------------------------------------------------------------------- 1 | 2 | # Hashed Indexes[](https://docs.mongodb.com/manual/core/index-hashed/#hashed-indexes "Permalink to this headline")哈希索引 3 | 4 | MongoDB Manual (Version 4.2)> Indexes > Hashed Indexes 5 | 6 | On this page 7 | 8 | - [Hashing Function](https://docs.mongodb.com/manual/core/index-hashed/#hashing-function哈希函数 9 | - [Create a Hashed Index](https://docs.mongodb.com/manual/core/index-hashed/#create-a-hashed-index)创建一个哈希索引 10 | - [Considerations](https://docs.mongodb.com/manual/core/index-hashed/#considerations)注意事项 11 | 12 | Hashed indexes maintain entries with hashes of the values of the indexed field. 13 | 哈希索引使用字段的哈希值构建索引。 14 | 15 | Hashed indexes support [sharding](https://docs.mongodb.com/manual/sharding/) using hashed shard keys. [Hashed based sharding](https://docs.mongodb.com/manual/core/hashed-sharding/#sharding-hashed-sharding) uses a hashed index of a field as the shard key to partition data across your sharded cluster. 16 | MongoDB分片中也支持哈希分片键。在分片集群中,如果数据记录的某字段使用哈希索引,在分片中仅需为该字段创建哈希分片键即可。 17 | 18 | Using a hashed shard key to shard a collection results in a more random distribution of data. See [Hashed Sharding](https://docs.mongodb.com/manual/core/hashed-sharding/#sharding-hashed-sharding) for more details. 19 | 在分片集群中对一个collection进行哈希分片会导致更多的数据随机分布,了解详情请参见 [Hashed Sharding](https://docs.mongodb.com/manual/core/hashed-sharding/#sharding-hashed-sharding) 。 20 | 21 | ## Hashing Function[](https://docs.mongodb.com/manual/core/index-hashed/#hashing-function "Permalink to this headline") 哈希函数 22 | 23 | Hashed indexes use a hashing function to compute the hash of the value of the index field. [[1]](https://docs.mongodb.com/manual/core/index-hashed/#hashvalue) The hashing function collapses embedded documents and computes the hash for the entire value but does not support multi-key (i.e. arrays) indexes. 24 | 哈希索引使用一个散列函数计算索引字段的哈希值。对于是嵌套文档的字段,哈希函数将计算整个嵌套文档的哈希值。在多键索引中不能使用哈希索引。 25 | 26 | > TIP 27 | > 提示: 28 | > 29 | > MongoDB automatically computes the hashes when resolving queries usinghashed indexes. Applications do **not** need to compute hashes. 30 | > MongoDB在执行使用到哈希索引的查询时自动计算哈希值,不需要应用程序自己计算查询字段的哈希值。 31 | 32 | [[1]](https://docs.mongodb.com/manual/core/index-hashed/#id1)Starting in version 4.0, the [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo "bin.mongo") shell provides the method [`convertShardKeyToHashed()`](https://docs.mongodb.com/manual/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed "convertShardKeyToHashed()"). This method uses the same hashing function as the hashed index and can be used to see what the hashed value would be for a key. 33 | [[1]](https://docs.mongodb.com/manual/core/index-hashed/#id1)从MongoDB 4.0开始,[`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo "bin.mongo") shell 提供 [`convertShardKeyToHashed()`](https://docs.mongodb.com/manual/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed "convertShardKeyToHashed()") 函数。该函数可以用来查看一个键的哈希值。 34 | ## Create a Hashed Index[](https://docs.mongodb.com/manual/core/index-hashed/#create-a-hashed-index "Permalink to this headline")创建哈希索引 35 | 36 | To create a [hashed index](https://docs.mongodb.com/manual/core/index-hashed/#index-type-hashed), specify `hashed` as the value of the index key, as in the following example: 37 | 对记录的指定字段创建哈希索引,命令如下: 38 | 39 | db.collection.createIndex( { _id: "hashed" } ) 40 | 41 | ## Considerations[](https://docs.mongodb.com/manual/core/index-hashed/#considerations "Permalink to this headline") 注意事项 42 | 43 | MongoDB supports `hashed` indexes of any single field. The hashing function collapses embedded documents and computes the hash for the entire value, but does not support multi-key (i.e. arrays) indexes. 44 | MongoDB支持对任何单一字段创建哈希索引,对于是嵌套文档的字段,哈希函数将计算整个嵌套文档的散列值,(例如:"a":{"b":"xxx","c":"xxx"},对于a字段创建哈希索引,哈希函数将计算整个{"b":"xxx","c":"xxx"}的散列值),但不支持在多键索引中使用哈希索引(例入:不可对属性是数组的字段创建哈希索引)。 45 | 46 | You may not create compound indexes that have `hashed` index fields or specify a unique constraint on a `hashed` index; however, you can create both a `hashed` index and an ascending/descending (i.e. non-hashed) index on the same field: MongoDB will use the scalar index for range queries. 47 | 我们不可在复合索引中使用哈希索引,也不可在哈希索引上指定唯一约束。但我们可以对同一字段创建一个哈希索引和非哈希索引(例入:升序/降序类索引):在进行范围查询时,MongoDB将自动选择升序/降序索引。 48 | 49 | ### 2^53^ Limit[](https://docs.mongodb.com/manual/core/index-hashed/#limit "Permalink to this headline") 2^53^限制 50 | 51 | > WARNING 注意 52 | > 53 | > MongoDB `hashed` indexes truncate floating point numbers to 64-bit integers before hashing. For example, a `hashed` index would store the same value for a field that held a value of `2.3`, `2.2`, and `2.9`. To prevent collisions, do not use a `hashed` index for floating point numbers that cannot be reliably converted to 64-bit integers (and then back to floating point). MongoDB `hashed` indexes do not support floating point values larger than 2^53^. 54 | > MongoDB哈希索引在计算散列之前将浮点数截断为64位整数。例如:对于哈希索引属性,数据内容为`2.3`, `2.2`, 和 `2.9`的记录对应的哈希列值是相同的。为了避免这种冲突,不建议对无法可靠转换成64位整数的浮点数属性字段创建哈希索引。MongoDB不支持对大于2^53^的浮点值使用哈希索引。 55 | 56 | To see what the hashed value would be for a key, see [`convertShardKeyToHashed()`](https://docs.mongodb.com/manual/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed "convertShardKeyToHashed()"). 57 | 查看键对应的哈希值请查看[`convertShardKeyToHashed()`](https://docs.mongodb.com/manual/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed "convertShardKeyToHashed()")。 58 | 59 | ### PowerPC and 2^63^[](https://docs.mongodb.com/manual/core/index-hashed/#powerpc-and-263 "Permalink to this headline") PowerPC 和 2^63^ 60 | 61 | For [hashed indexes](https://docs.mongodb.com/manual/core/index-hashed/#), MongoDB 4.2 ensures that the hashed value for the floating point value 2^63^ on PowerPC is consistent with other platforms. 62 | PowerPC和其他处理器中,MongoDB 4.2都保证可以计算64位(8字节)双精度浮点数(-1.79E+308 ~ +1.79E+308)的哈希值。 63 | 64 | Although [hashed indexes](https://docs.mongodb.com/manual/core/index-hashed/#) on a field that may contain floating point values greater than 2^53^ is an unsupported configuration, clients may still insert documents where the indexed field has the value 2^63^. 65 | 虽然大于2^53^的浮点数属性是无法配置的,但是客户端仍然可以插入索引字段值是2^63^的文档。 66 | 67 | To list all `hashed` indexes for all collections in your deployment, you can use the following operation in the [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo "bin.mongo") shell: 68 | 查询部署的MongoDB实例中所有数据库中所有collection中的哈希索引,可以在[`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo "bin.mongo") shell中使用如下命令: 69 | 70 | db.adminCommand("listDatabases").databases.forEach(function(d){ 71 | let mdb = db.getSiblingDB(d.name); 72 | mdb.getCollectionInfos({ type: "collection" }).forEach(function(c){ 73 | let currentCollection = mdb.getCollection(c.name); 74 | currentCollection.getIndexes().forEach(function(idx){ 75 | let idxValues = Object.values(Object.assign({}, idx.key)); 76 | 77 | if (idxValues.includes("hashed")) { 78 | print("Hashed index: " + idx.name + " on " + idx.ns); 79 | printjson(idx); 80 | }; 81 | }); 82 | }); 83 | }); 84 | 85 | To check if the indexed field contains the value 2^63^, run the following operation for the collection and the indexed field: 86 | 检查某个collection的索引字段数据内容是2^63^位的值,使用如下命令: 87 | - If the indexed field type is a scalar and never a document: 88 | - 如果一个collection中的索引字段数据内容仅是数值,不存在任何文档: 89 | 90 | ``` 91 | // substitute the actual collection name for 92 | // substitute the actual indexed field name for 93 | 94 | db..find( { : Math.pow(2,63) } ); 95 | ``` 96 | 97 | - If the indexed field type is a document (or a scalar), you can run: 98 | - 如果一个collection中的索引字段是文档(或者数值),可以执行: 99 | 100 | 101 | ``` 102 | // substitute the actual collection name for 103 | // substitute the actual indexed field name for 104 | 105 | db..find({ 106 | $where: function() { 107 | function findVal(obj, val) { 108 | if (obj === val) 109 | return true; 110 | 111 | for (const child in obj) { 112 | if (findVal(obj[child], val)) { 113 | return true; 114 | } 115 | } 116 | return false; 117 | } 118 | return findVal(this., Math.pow(2, 63)); 119 | } 120 | }) 121 | ``` 122 | 123 | 原文链接:[https://docs.mongodb.com/manual/core/index-hashed/#hashed-indexes](https://docs.mongodb.com/manual/core/index-hashed/#hashed-indexes) 124 | 125 | 译者:程哲欣 126 | 127 | -------------------------------------------------------------------------------- /08 Indexes 索引/08-11 Index Properties 索引属性.md: -------------------------------------------------------------------------------- 1 | 2 | In addition to the numerous index types MongoDB supports, indexes can also have various properties. The following documents detail the index properties that you can select when building an index. 3 | 4 | 除了 MongoDB支持的众多索引类型外,索引还可以具有各种属性。以下文档详细介绍了在建立索引时可以选择的索引属性。 5 | 6 | 7 | ### [TTL Indexes TTL索引](https://docs.mongodb.com/manual/core/index-ttl/) 8 | 9 | The TTL index is used for TTL collections, which expire data after a period of time. 10 | 11 | TTL索引用于TTL收集,这些收集会在一段时间后使数据过期。 12 | 13 | ### [Unique Indexes 唯一索引](https://docs.mongodb.com/manual/core/index-unique/) 14 | 15 | A unique index causes MongoDB to reject all documents that contain a duplicate value for the indexed field. 16 | 17 | 唯一索引会导致MongoDB拒绝所有包含索引字段重复值的文档。 18 | 19 | ### [Partial Indexes 部分索引](https://docs.mongodb.com/manual/core/index-partial/) 20 | 21 | A partial index indexes only documents that meet specified filter criteria. 22 | 23 | 部分索引仅索引符合指定过滤条件的文档。 24 | 25 | ### [Case Insensitive Indexes 不区分大小写索引](https://docs.mongodb.com/manual/core/index-case-insensitive/) 26 | 27 | A case insensitive index disregards the case of the index key values. 28 | 29 | 不区分大小写的索引会忽略索引键值的大小写。 30 | 31 | ### [Sparse Indexes 稀疏索引](https://docs.mongodb.com/manual/core/index-sparse/) 32 | 33 | A sparse index does not index documents that do not have the indexed field. 34 | 35 | 稀疏索引不会索引没有索引字段的文档。 36 | 37 | 38 | ----------------- 39 | 40 | ## Index Properties[](#index-properties "Permalink to this headline") 索引属性 41 | 42 | ### Unique Indexes[](#unique-indexes "Permalink to this headline") 唯一索引 43 | 44 | The [unique](https://docs.mongodb.com/manual/core/index-unique.html) property for an index causes MongoDB to reject duplicate values for the indexed field. Other than the unique constraint, unique indexes are functionally interchangeable with other MongoDB indexes. 45 | 开启[unique](https://docs.mongodb.com/manual/core/index-unique.html)选项,索引对应字段具有唯一性,对应字段拒绝重复值。除唯一性约束外,在功能上,索引的unique特性可与其他特性交替使用。 46 | 47 | ### Partial Indexes[](#partial-indexes "Permalink to this headline") 部分索引 48 | 49 | New in version 3.2. 50 | 3.2版本新特性 51 | 52 | [Partial indexes](https://docs.mongodb.com/manual/core/index-partial.html) only index the documents in a collection that meet a specified filter expression. By indexing a subset of the documents in a collection, partial indexes have lower storage requirements and reduced performance costs for index creation and maintenance. 53 | [Partial](https://docs.mongodb.com/manual/core/index-partial.html)特性相关选项设置后,将仅索引集合中满足指定筛选表达式的文档。对集合中的文档子集创建索引,设置了partial特性的索引将占用更低的存储,并降低mongodb创建索引和维护索引的性能开销。 54 | 55 | Partial indexes offer a superset of the functionality of sparse indexes and should be preferred over sparse indexes. 56 | 在功能上,索引的Partial特性是sparse特性的超集,当一个索引同时拥有两种特性时,以Partial特性优先。 57 | 58 | ### Sparse Indexes[](#sparse-indexes "Permalink to this headline") 稀疏索引 59 | 60 | The [sparse](https://docs.mongodb.com/manual/core/index-sparse.html) property of an index ensures that the index only contain entries for documents that have the indexed field. The index skips documents that _do not_ have the indexed field. 61 | 索引的sparse特性确保只对存在索引字段的文档创建索引。创建索引时将会跳过那些没有对应字段值的文档。 62 | 63 | You can combine the sparse index option with the unique index option to prevent inserting documents that have duplicate values for the indexed field(s) and skip indexing documents that lack the indexed field(s). 64 | 你或许可以将sparse选项和unique选项结合使用,以防止索引字段插入重复值,并对对应索引字段缺失的文档不创建索引,提升数据库效率。 65 | 66 | ### TTL Indexes[](#ttl-indexes "Permalink to this headline") TTL索引 67 | 68 | [TTL indexes](https://docs.mongodb.com/manual/core/index-ttl.html) are special indexes that MongoDB can use to automatically remove documents from a collection after a certain amount of time. This is ideal for certain types of information like machine generated event data, logs, and session information that only need to persist in a database for a finite amount of time. 69 | 索引的[TTL](https://docs.mongodb.com/manual/core/index-ttl.html)特性,允许MongoDB在一定时间后自动从集合中移除文档。这非常适合某些类型的信息,例如:机器生成的事件数据、日志和会话信息,这些信息只需要在数据库中保留有限的时间。 70 | 71 | See: [Expire Data from Collections by Setting TTL](https://docs.mongodb.com/manual/tutorial/expire-data.html) for implementation instructions. 72 | 有关实现说明,请参见:[Expire Data from Collections by Setting TTL](https://docs.mongodb.com/manual/tutorial/expire-data.html) 73 | 74 | 75 | 76 | 原文链接:https://docs.mongodb.com/manual/core/index-properties/ 77 | 78 | 译者:程哲欣 79 | -------------------------------------------------------------------------------- /08 Indexes 索引/08-15 Measure Index Use 度量索引使用情况.md: -------------------------------------------------------------------------------- 1 | # Measure Index Use[](https://docs.mongodb.com/manual/tutorial/measure-index-use/#measure-index-use "Permalink to this headline") 度量索引使用情况 2 | 3 | On this page 4 | 5 | - [Get Index Access Information with `$indexStats`](https://docs.mongodb.com/manual/tutorial/measure-index-use/#get-index-access-information-with-indexstats) 使用$indexStats度量索引使用 6 | - [Return Query Plan with `explain()`](https://docs.mongodb.com/manual/tutorial/measure-index-use/#return-query-plan-with-explain) 使用 `explain()`返回查询计划 7 | - [Control Index Use with `hint()`](https://docs.mongodb.com/manual/tutorial/measure-index-use/#control-index-use-with-hint) 使用`hint()`控制索引使用 8 | - [Index Metrics](https://docs.mongodb.com/manual/tutorial/measure-index-use/#index-metrics) 其他索引度量方法 9 | 10 | ## Get Index Access Information with `$indexStats`[](https://docs.mongodb.com/manual/tutorial/measure-index-use/#get-index-access-information-with-indexstats "Permalink to this headline") 使用$indexStats度量索引使用 11 | 12 | 13 | Use the [`$indexStats`](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/#pipe._S_indexStats "$indexStats") aggregation stage to get statistics regarding the use of each index for a collection. For example, the following aggregation operation returns statistics on the index use on the `orders` 14 | collection: 15 | 在aggregate操作时使用[`$indexStats`](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/#pipe._S_indexStats "$indexStats") 参数获取集合的每个索引使用情况的统计信息。例如:如下语句将返回`orders`表的索引使用统计信息 16 | 17 | db.orders.aggregate( [ { $indexStats: { } } ] ) 18 | 19 | SEE ALSO 20 | 也可参考: 21 | 22 | [`$indexStats`](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/#pipe._S_indexStats "$indexStats") 23 | 24 | ## Return Query Plan with `explain()`[](https://docs.mongodb.com/manual/tutorial/measure-index-use/#return-query-plan-with-explain "Permalink to this headline") 使用 `explain()`返回查询计划 25 | 26 | Use the [`db.collection.explain()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()") or the [`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()") method in [executionStats](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#explain-method-executionstats) mode to return statistics about the query process, including the index used, the number of documents scanned, and the time the query takes to process in milliseconds. 27 | 在[executionStats](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#explain-method-executionstats) 模式下使用 [`db.collection.explain()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()") 或[`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()")方法返回语句查询过程的统计信息,包括索引使用,文档遍历数量,和查询处理所需的时间。 28 | 29 | Run [`db.collection.explain()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()") or the [`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()") method in [allPlansExecution](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#explain-method-allplansexecution) mode to view partial execution statistics collected during plan selection. 30 | 在[allPlansExecution](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#explain-method-allplansexecution) 模式下使用 [`db.collection.explain()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()") 或[`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()")方法查看计划选择期间收集的部分执行统计信息。 31 | 32 | SEE ALSO 33 | 也可参考: 34 | 35 | [planCacheKey](https://docs.mongodb.com/manual/core/query-plans/#plan-cache-key) 36 | 37 | ## Control Index Use with `hint()`[](https://docs.mongodb.com/manual/tutorial/measure-index-use/#control-index-use-with-hint "Permalink to this headline") 使用`hint()`控制索引使用 38 | 39 | To _force_ MongoDB to use a particular index for a [`db.collection.find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()") operation, specify the index with the[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()") method. Append the [`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()") method to the [`find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()") method. Consider the following example: 40 | 强制MongoDB在执行[`db.collection.find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()")相关命令时使用特定索引,在[`find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()")方法后追加[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")方法,并将特定索引在[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")方法中声明。 41 | 代码示例如下: 42 | 43 | db.people.find( 44 | { name: "John Doe", zipcode: { $gt: "63000" } } 45 | ).hint( { zipcode: 1 } ) 46 | 47 | To view the execution statistics for a specific index, append to the [`db.collection.find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()") the [`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")method followed by [`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()"), e.g.: 48 | 查看使用特定索引的执行统计信息,在[`db.collection.find()`](https://docs.mongodb.com/manual/reference/method/db.collection.find/#db.collection.find "db.collection.find()")语句追加的[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")方法后跟随[`cursor.explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain "cursor.explain()")方法,代码示例如下: 49 | 50 | db.people.find( 51 | { name: "John Doe", zipcode: { $gt: "63000" } } 52 | ).hint( { zipcode: 1 } ).explain("executionStats") 53 | 54 | Or, append [`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()") method to [`db.collection.explain().find()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()"): 55 | 或者在[`db.collection.explain().find()`](https://docs.mongodb.com/manual/reference/method/db.collection.explain/#db.collection.explain "db.collection.explain()")方法后追加[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")方法。 56 | 57 | db.people.explain("executionStats").find( 58 | { name: "John Doe", zipcode: { $gt: "63000" } } 59 | ).hint( { zipcode: 1 } ) 60 | 61 | Specify the `$natural` operator to the [`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()") method to prevent MongoDB from using _any_ index: 62 | 在[`hint()`](https://docs.mongodb.com/manual/reference/method/cursor.hint/#cursor.hint "cursor.hint()")方法中声明`$natural`参数,避免MongoDB在查询过程中使用任何索引。 63 | 64 | db.people.find( 65 | { name: "John Doe", zipcode: { $gt: "63000" } } 66 | ).hint( { $natural: 1 } ) 67 | 68 | ## Index Metrics[](https://docs.mongodb.com/manual/tutorial/measure-index-use/#index-metrics "Permalink to this headline") 其他索引度量方法 69 | 70 | In addition to the [`$indexStats`](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/#pipe._S_indexStats "$indexStats") aggregation stage, MongoDB provides various index statistics that you may want to consider when analyzing index use for your database: 71 | 当你在分析数据的索引使用情况时,除了在aggregate过程中声明[`$indexStats`](https://docs.mongodb.com/manual/reference/operator/aggregation/indexStats/#pipe._S_indexStats "$indexStats")参数外,亦可使用如下几种方法统计索引使用。 72 | | | | 73 | |--|--| 74 | | In the output of [`serverStatus`](https://docs.mongodb.com/manual/reference/command/serverStatus/#dbcmd.serverStatus "serverStatus"): 75 | 在[`serverStatus`](https://docs.mongodb.com/manual/reference/command/serverStatus/#dbcmd.serverStatus "serverStatus")方法的输出结果中: | [`metrics.queryExecutor.scanned`](https://docs.mongodb.com/manual/reference/command/serverStatus/#serverstatus.metrics.queryExecutor.scanned "metrics.queryExecutor.scanned")和[`metrics.operation.scanAndOrder`](https://docs.mongodb.com/manual/reference/command/serverStatus/#serverstatus.metrics.operation.scanAndOrder "metrics.operation.scanAndOrder") | 76 | | In the output of [`collStats`](https://docs.mongodb.com/manual/reference/command/collStats/#dbcmd.collStats "collStats"):在[`collStats`](https://docs.mongodb.com/manual/reference/command/collStats/#dbcmd.collStats "collStats")输出结果 | [`totalIndexSize`](https://docs.mongodb.com/manual/reference/command/collStats/#collStats.totalIndexSize "collStats.totalIndexSize")和[`indexSizes`](https://docs.mongodb.com/manual/reference/command/collStats/#collStats.indexSizes "collStats.indexSizes") | 77 | | In the output of [`dbStats`](https://docs.mongodb.com/manual/reference/command/dbStats/#dbcmd.dbStats "dbStats"):在[`dbStats`](https://docs.mongodb.com/manual/reference/command/dbStats/#dbcmd.dbStats "dbStats")输出结果 | [`dbStats.indexes`](https://docs.mongodb.com/manual/reference/command/dbStats/#dbStats.indexes "dbStats.indexes")和[`dbStats.indexSize`](https://docs.mongodb.com/manual/reference/command/dbStats/#dbStats.indexSize "dbStats.indexSize") | 78 | 79 | 80 | 81 | 原文链接:https://docs.mongodb.com/manual/tutorial/measure-index-use/#measure-index-use 82 | 83 | 译者:程哲欣 84 | -------------------------------------------------------------------------------- /09 Security 安全/09-04 Authentication 身份验证.md: -------------------------------------------------------------------------------- 1 | # Authentication 2 | 3 | # 身份验证 4 | 5 | On this page 6 | 7 | - [Authentication Methods](https://docs.mongodb.com/manual/core/authentication/#authentication-methods) 8 | - [Authentication Mechanisms](https://docs.mongodb.com/manual/core/authentication/#authentication-mechanisms) 9 | - [Internal Authentication](https://docs.mongodb.com/manual/core/authentication/#internal-authentication) 10 | - [Authentication on Sharded Clusters](https://docs.mongodb.com/manual/core/authentication/#authentication-on-sharded-clusters) 11 | 12 | 在本页面 13 | 14 | - 身份验证方法 15 | - 身份验证机制 16 | - 内部身份验证 17 | - 分片集群中的身份验证 18 | 19 | Authentication is the process of verifying the identity of a client. When access control, i.e. [authorization](https://docs.mongodb.com/manual/core/authorization/), is enabled, MongoDB requires all clients to authenticate themselves in order to determine their access. 20 | 21 | 身份验证是验证客户端身份的过程。当访问控制(即授权)开启的时候,MongoDB要求所有客户端进行身份认证,以确定他们的访问权限。 22 | 23 | Although authentication and [authorization](https://docs.mongodb.com/manual/core/authorization/) are closely connected, authentication is distinct from authorization. Authentication verifies the identity of a user; authorization determines the verified user’s access to resources and operations. 24 | 25 | 尽管身份认证和授权紧密相连,但是身份认证和授权是不同的。身份认证是验证用户的身份,授权决定已通过验证的用户对资源和操作的访问权限。 26 | 27 | ## Authentication Methods 28 | 29 | ## 身份验证的方法 30 | 31 | To authenticate as a user, you must provide a username, password, and the [authentication database](https://docs.mongodb.com/manual/reference/program/mongo/#mongo-shell-authentication-options) associated with that user. 32 | 33 | 作为一个用户要进行身份验证,你必须提供一个用户名、密码和关联这个用户的认证数据库。 34 | 35 | To authenticate using the [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell, either: 36 | 37 | - Use the [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) command-line authentication options ([`--username`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-username), [`--password`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-password), and [`--authenticationDatabase`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-authenticationdatabase)) when connecting to the [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) or [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instance, or 38 | - Connect first to the [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) or [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instance, and then run the [`authenticate`](https://docs.mongodb.com/manual/reference/command/authenticate/#dbcmd.authenticate) command or the [`db.auth()`](https://docs.mongodb.com/manual/reference/method/db.auth/#db.auth) method against the [authentication database](https://docs.mongodb.com/manual/reference/program/mongo/#mongo-shell-authentication-options). 39 | 40 | 使用mongo shell 进行身份验证,可以: 41 | 42 | - 当连接mongod或者mongos实例时,使用mongo命令行认证选项(--username、--password和--authenticationDatabase),也可以 43 | - 先连接mongod或者mongos实例,然后在认证数据库上运行authenticate命令或者db.auth()方法。 44 | 45 | > IMPORTANT: 46 | > 47 | > Authenticating multiple times as different users does **not** drop the credentials of previously-authenticated users. This may lead to a connection having more permissions than intended by the user, and causes operations within a [logical session](https://docs.mongodb.com/manual/reference/server-sessions/) to raise an error. 48 | 49 | > 重要: 50 | > 51 | > 当使用不同的用户进行多次身份验证时,不会删除已经通过身份认证的用户的凭证。这可能导致这个进行过多个用户身份认证的连接具有比用户预期更多的权限,并导致在一个逻辑会话中的操作引发错误。 52 | 53 | For examples of authenticating using a MongoDB driver, see the [driver documentation](https://docs.mongodb.com/ecosystem/drivers/). 54 | 55 | 关于使用MongoDB驱动程序进行身份验证的示例,请参阅驱动程序文档。 56 | 57 | ## Authentication Mechanisms 58 | 59 | ## 身份验证机制 60 | 61 | MongoDB supports a number of [authentication mechanisms](https://docs.mongodb.com/manual/core/authentication-mechanisms/#security-authentication-mechanisms) that clients can use to verify their identity. These mechanisms allow MongoDB to integrate into your existing authentication system. 62 | 63 | MongoDB支持许多身份认证机制,客户端可以使用这些身份认证机制来验证自己的身份。MongoDB允许集成这些机制到已经存在的身份认证系统。 64 | 65 | MongoDB supports multiple authentication mechanisms: 66 | 67 | - [SCRAM](https://docs.mongodb.com/manual/core/security-scram/#authentication-scram) (*Default*) 68 | - [x.509 Certificate Authentication](https://docs.mongodb.com/manual/core/security-x.509/#security-auth-x509). 69 | 70 | MongoDB支持多种身份验证机制: 71 | 72 | - SCRAM(默认的) 73 | - x.509证书身份验证 74 | 75 | ## Internal Authentication 76 | 77 | ## 内部身份验证 78 | 79 | In addition to verifying the identity of a client, MongoDB can require members of replica sets and sharded clusters to [authenticate their membership](https://docs.mongodb.com/manual/core/security-internal-authentication/#inter-process-auth) to their respective replica set or sharded cluster. See [Internal/Membership Authentication](https://docs.mongodb.com/manual/core/security-internal-authentication/#inter-process-auth) for more information. 80 | 81 | 除了验证客户端的身份之外,MongoDB能要求副本集和分片集群的成员对其各自的副本集或者分片集群的成员资格进行身份验证。更多的信息请参阅:内部/成员身份认证。 82 | 83 | ## Authentication on Sharded Clusters 84 | 85 | ## 分片集群的身份验证 86 | 87 | In sharded clusters, clients generally authenticate directly to the [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instances. However, some maintenance operations may require authenticating directly to a specific shard. For more information on authentication and sharded clusters, see [Sharded Cluster Users](https://docs.mongodb.com/manual/core/security-users/#sharding-security). 88 | 89 | 在分片集群中,客户端通常直接向mongos实例进行身份认证。然而,一些维护操作可能要求对特定的分片进行认证。更多关于身份认证和分片集群的信息,请参阅分片集群用户。 90 | 91 | 92 | 93 | 原文链接:https://docs.mongodb.com/manual/core/authentication/ 94 | 95 | 译者:傅立 96 | -------------------------------------------------------------------------------- /09 Security 安全/09-09 Auditing 审计.md: -------------------------------------------------------------------------------- 1 | # Auditing[](https://docs.mongodb.com/manual/core/auditing/) 2 | # 审计 3 | On this page 4 | 5 | - [Enable and Configure Audit Output]启用和配置审计输出(https://docs.mongodb.com/manual/core/auditing/#enable-and-configure-audit-output) 6 | - [Audit Events and Filter]审计事件和过滤器(https://docs.mongodb.com/manual/core/auditing/#audit-events-and-filter) 7 | - [Audit Guarantee]审计保证 8 | (https://docs.mongodb.com/manual/core/auditing/#audit-guarantee) 9 | 10 | MongoDB Enterprise includes an auditing capability for mongod and mongos instances. The auditing facility allows administrators and users to track system activity for deployments with multiple users and applications. 11 | MongoDB 企业版包含针对 mongod 和 mongos 实例的审计功能 。审核功能使管理员和用户可以跟踪具有多个用户和多个客户端应用的 mongodb 的运行情况。 12 | 13 | 14 | ## Enable and Configure Audit Output[](https://docs.mongodb.com/manual/core/auditing/#enable-and-configure-audit-output) 15 | ## 启用和配置审计输出 16 | The auditing facility can write audit events to the console, the syslog, a JSON file, or a BSON file. To enable auditing for MongoDB Enterprise, see Configure Auditing. 17 | 审计功能可以将审计事件写入控制台console,syslog,JSON 文件或 BSON 文件。要为 MongoDB 企业版启用审计,请参阅[配置审计](https://docs.mongodb.com/manual/tutorial/configure-auditing/)。 18 | 19 | For information on the audit log messages, see System Event Audit Messages. 20 | 有关审计日志消息的信息,请参阅[系统事件审计消息](https://docs.mongodb.com/manual/reference/audit-message/)。 21 | 22 | ## Audit Events and Filter[](https://docs.mongodb.com/manual/core/auditing/#audit-events-and-filter) 23 | ## 审计事件和过滤器 24 | Once enabled, the auditing system can record the following operations [1]: 25 | 启用后,审计系统可以记录以下操作[1]: 26 | 27 | - schema (DDL), 28 | - replica set and sharded cluster, 29 | - authentication and authorization, and 30 | - CRUD operations (requires auditAuthorizationSuccess set to true). 31 | 32 | - 模式(DDL), 33 | - 副本集集群和分片集群, 34 | - 认证和授权,以及 35 | - CRUD操作(要求auditAuthorizationSuccess设置为true)。 36 | 37 | For details on audited actions, see Audit Event Actions, Details, and Results. 38 | 有关审计的操作的详细信息,请参阅[审计事件操作,详细信息和结果](https://docs.mongodb.com/manual/reference/audit-message/#audit-action-details-results)。 39 | 40 | With the auditing system, you can set up filters to restrict the events captured. To set up filters, see Configure Audit Filters. 41 | 使用审计系统,您可以[设置过滤器](https://docs.mongodb.com/manual/tutorial/configure-audit-filters/#audit-filter)以限制捕获的事件。要设置过滤器,请参阅[“配置审计过滤器”](https://docs.mongodb.com/manual/tutorial/configure-audit-filters/)。 42 | 43 | [1] Operations in an aborted transaction still generate audit events. However, there is no audit event that indicates that the transaction aborted. 44 | 在一个被中止的事务中[1]中的操作任然会生成一个审计事件,但是没有一个审计事件指示事务被中止了。 45 | 46 | ## Audit Guarantee[](https://docs.mongodb.com/manual/core/auditing/#audit-guarantee) 47 | ## 审计保证 48 | 49 | The auditing system writes every audit event [2] to an in-memory buffer of audit events. MongoDB writes this buffer to disk periodically. For events collected from any single connection, the events have a total order: if MongoDB writes one event to disk, the system guarantees that it has written all prior events for that connection to disk. 50 | 审计系统将每个审计事件[2](https://docs.mongodb.com/manual/core/auditing/#filter)写入审计事件的内存缓冲区中。MongoDB定期将此缓冲区写入磁盘。对于从任何单个连接收集的事件,这些事件具有总顺序:如果MongoDB将一个事件写入磁盘,系统将保证已将该连接的所有先前事件写入磁盘。 51 | 52 | If an audit event entry corresponds to an operation that affects the durable state of the database, such as a modification to data, MongoDB will always write the audit event to disk before writing to the journal for that entry. 53 | 如果审计事件条目对应的操作影响数据库的持久状态,如修改数据的操作,则MongoDB始终会在将审计事件写入磁盘之前将事件条目写入日志 54 | 55 | That is, before adding an operation to the journal, MongoDB writes all audit events on the connection that triggered the operation, up to and including the entry for the operation. 56 | 也就是说,在将操作添加到[日志](https://docs.mongodb.com/manual/reference/glossary/#term-journal)之前,MongoDB会在触发该操作的连接上写入所有审计事件,直到并包括该操作的条目。 57 | 58 | These auditing guarantees require that MongoDB run with journaling enabled. 59 | 这些审计保证要求MongoDB在[journaling](https://docs.mongodb.com/manual/reference/configuration-options/#storage.journal.enabled)启用的情况下运行 。 60 | 61 | ## WARNING 62 | ## 警告 63 | MongoDB may lose events if the server terminates before it commits the events to the audit log. The client may receive confirmation of the event before MongoDB commits to the audit log. 64 | 如果服务器在将事件提交到审计日志之前终止,则MongoDB可能会丢失事件。在MongoDB提交审计日志之前,客户端可能会收到事件确认。 65 | For example, while auditing an aggregation operation, the server might crash after returning the result but before the audit log flushes. 66 | 例如,在审计聚合操作时,服务器可能在返回结果之后但在刷新审计日志之前崩溃。 67 | 68 | [2] Audit configuration can include a filter to limit events to audit. 69 | [2](https://docs.mongodb.com/manual/core/auditing/#id3)审计配置可以包括一个[筛选器](https://docs.mongodb.com/manual/tutorial/configure-audit-filters/#audit-filter),以限制要审计的事件。 70 | 71 | ## 附录: 72 | Configure Auditing 配置审计:[https://docs.mongodb.com/manual/tutorial/configure-auditing/](https://docs.mongodb.com/manual/tutorial/configure-auditing/) 73 | 74 | Configure Audit Filters 配置审计过滤器:[https://docs.mongodb.com/manual/tutorial/configure-audit-filters/](https://docs.mongodb.com/manual/tutorial/configure-audit-filters/) 75 | 76 | System Event Audit Messages 系统事件审计消息: [https://docs.mongodb.com/manual/reference/audit-message/](https://docs.mongodb.com/manual/reference/audit-message/) 77 | 78 | 79 | 80 | 原文链接:https://docs.mongodb.com/manual/core/auditing/ 81 | 82 | 译者:谢伟成 83 | -------------------------------------------------------------------------------- /09 Security 安全/09-10 Network and Configuration Hardening 网络和配置强化.md: -------------------------------------------------------------------------------- 1 | # Network and Configuration Hardening[](https://docs.mongodb.com/manual/core/security-hardening/ "Permalink to this headline") 2 | 3 | # 网络和配置强化 4 | 5 | 6 | - [MongoDB Configuration Hardening]MongoDB 配置强化(https://docs.mongodb.com/manual/core/security-hardening/#mongodb-configuration-hardening) 7 | - [Network Hardening]网络强化(https://docs.mongodb.com/manual/core/security-hardening/#network-hardening) 8 | 9 | To reduce the risk exposure of the entire MongoDB system, ensure that only trusted hosts have access to MongoDB. 10 | 要降低整个 MongoDB 系统的风险暴露,请确保只有可信主机才能访问 MongoDB。 11 | 12 | ## MongoDB Configuration Hardening 13 | 14 | ## MongoDB 配置强化 15 | 16 | ### IP Binding 17 | 18 | ### IP绑定 19 | 20 | Starting with MongoDB 3.6, MongoDB binaries, [mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) and [mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos), bind to localhost by default. From MongoDB versions 2.6 to 3.4, only the binaries from the official MongoDB RPM (Red Hat, CentOS, Fedora Linux, and derivatives) and DEB (Debian, Ubuntu, and derivatives) packages would bind to localhost by default. To learn more about this change, see [Localhost Binding Compatibility Changes.](https://docs.mongodb.com/manual/release-notes/3.6-compatibility/#bind-ip-compatibility) 21 | 从MongoDB 3.6开始,MongoDB 二进制文件, [mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) 和 [mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) 默认绑定本地主机(localhost)。从MongoDB 版本 2.6 到 3.4,只有官方 MongoDB RPM安装包(Red Hat,CentOS,Fedora Linux 和衍生产品)和 DEB安装包(Debian,Ubuntu 及衍生产品)中的二进制文件默认绑定到本地主机(localhost)。要了解有关此更改的更多信息,请参阅 [本地主机绑定兼容性更改](https://docs.mongodb.com/manual/release-notes/3.6-compatibility/#bind-ip-compatibility)。 22 | 23 | WARNING: 24 | 警告: 25 | 26 | Before binding to a non-localhost (e.g. publicly accessible) IP address, ensure you have secured your cluster from unauthorized access. For a complete list of security recommendations, see [Security Checklist](https://docs.mongodb.com/manual/administration/security-checklist/). At minimum, consider [enabling authentication](https://docs.mongodb.com/manual/administration/security-checklist/#checklist-auth) and [hardening network infrastructure](https://docs.mongodb.com/manual/core/security-hardening/#). 27 | 在绑定到非本地主机(例如可公开访问的) IP 地址之前,请确保已保护数据库集群防止未经授权的访问。有关安全建议的完整列表,请参阅[安全检查表](https://docs.mongodb.com/manual/administration/security-checklist/)。至少需要要考虑 [启用身份验证](https://docs.mongodb.com/manual/administration/security-checklist/#checklist-auth) 和施[强化网络基础架构](https://docs.mongodb.com/manual/core/security-hardening/#)。 28 | 29 | WARNING: 30 | 重要提示: 31 | 32 | Make sure that your [mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) and [mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instances are only accessible on trusted networks. If your system has more than one network interface, bind MongoDB programs to the private or internal network interface. 33 | 确保只能在受信任的网络上访问 [mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) 和[mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos)实例。如果您的系统具有多个网络接口,请将 MongoDB 程序绑定到专用或内部网络接口。 34 | 35 | For more information, see [IP Binding](https://docs.mongodb.com/manual/core/security-mongodb-configuration/). 36 | 更多的信息,参照 [IP 绑定](https://docs.mongodb.com/manual/core/security-mongodb-configuration/)。 37 | 38 | ### HTTP Status Interface and REST API 39 | 40 | ### HTTP状态接口和REST API 41 | 42 | *Changed in version 3.6:* MongoDB 3.6 removes the deprecated HTTP interface and REST API to MongoDB. 43 | 3.6版本的变化: MongoDB 3.6 移除了 MongoDB数据库的HTTP Interface 和REST API。 44 | 45 | ## Network Hardening 46 | 47 | ## 网络强化 48 | 49 | ### Firewalls 50 | 51 | ### 防火墙 52 | 53 | Firewalls allow administrators to filter and control access to a system by providing granular control over network communications. For administrators of MongoDB, the following capabilities are important: limiting incoming traffic on a specific port to specific systems and limiting incoming traffic from untrusted hosts. 54 | 防火墙允许管理员通过提供网络通信的细粒度控制来过滤和控制对系统的访问。对于 MongoDB 的管理员,以下功能非常重要:将特定端口上的传入流量限制到特定系统,并限制来自不受信任主机的传入流量。 55 | 56 | On Linux systems, the **iptables** interface provides access to the underlying **netfilter** firewall. On Windows systems, **netsh** command line interface provides access to the underlying Windows Firewall. For additional information about firewall configuration, see: 57 | 58 | 在 Linux 系统上,**iptables **接口提供对底层 **netfilter** 防火墙的访问。在 Windows 系统上**,netsh** 命令 line 接口提供对底层 Windows 防火墙的访问。有关防火墙配置的其他信息,请参阅: 59 | 60 | - [Configure Linux iptables Firewall for MongoDB]为 MongoDB 配置 Linux iptables 防火墙(https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/) 61 | - [Configure Windows netsh Firewall for MongoDB]为 MongoDB 配置 Windows netsh 防火墙(https://docs.mongodb.com/manual/tutorial/configure-windows-netsh-firewall/) 62 | 63 | For best results and to minimize overall exposure, ensure that *only* traffic from trusted sources can reach [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) and [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instances and that the [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) and [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos) instances can only connect to trusted outputs. 64 | 为了获得最佳结果并最大限度地减少总体风险,请确保只有来自可靠来源的流量才能到达[mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod)和[mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos)实例,并且[mongod](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod)和[mongos](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos)实例只能连接到受信任的输出。 65 | 66 | ### Virtual Private Networks 67 | 68 | ### 虚拟专用网 69 | 70 | Virtual private networks, or VPNs, make it possible to link two networks over an encrypted and limited-access trusted network. Typically, MongoDB users who use VPNs use TLS/SSL rather than IPSEC VPNs for performance issues. 71 | 虚拟专用网络或VPN使得通过加密和有限访问的可信网络连接两个网络成为可能。通常,使用 VPN 的 MongoDB 用户使用 TLS/SSL 而不是 IPSEC VPN 来解决性能问题。 72 | 73 | Depending on configuration and implementation, VPNs provide for certificate validation and a choice of encryption protocols, which requires a rigorous level of authentication and identification of all clients. Furthermore, because VPNs provide a secure tunnel, by using a VPN connection to control access to your MongoDB instance, you can prevent tampering and “man-in-the-middle” attacks.| 74 | 根据配置和实现,VPN 提供证书验证和加密协议选择,这需要对所有客户端进行严格的身份验证和识别。此外,由于 VPN 提供了一个安全通道,通过使用 VPN 连接来控制对 MongoDB 实例的访问,您可以防止篡改和“中间人”攻击。 75 | 76 | ## 附录 77 | 78 | IP Binding IP绑定:[https://docs.mongodb.com/manual/core/security-mongodb-configuration/](https://docs.mongodb.com/manual/core/security-mongodb-configuration/) 79 | 80 | Configure Linux `iptables` Firewall for MongoDB `iptables`为MongoDB 配置Linux 防火墙:[https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/](https://docs.mongodb.com/manual/tutorial/configure-linux-iptables-firewall/) 81 | 82 | Configure Windows `netsh` Firewall for MongoDB `netsh`为MongoDB 配置Windows 防火墙:[https://docs.mongodb.com/manual/tutorial/configure-windows-netsh-firewall/](https://docs.mongodb.com/manual/tutorial/configure-windows-netsh-firewall/) 83 | 84 | Implement Field Level Redaction实施字段级别修订:[https://docs.mongodb.com/manual/tutorial/implement-field-level-redaction/](https://docs.mongodb.com/manual/tutorial/implement-field-level-redaction/) 85 | 86 | 87 | 原文链接:[https://docs.mongodb.com/manual/core/security-hardening/](https://docs.mongodb.com/manual/core/security-hardening/) 88 | 89 | 译者:孔令升 90 | -------------------------------------------------------------------------------- /09 Security 安全/09-12 Security Reference 安全参考.md: -------------------------------------------------------------------------------- 1 | # Security Reference 2 | 3 | # 安全参考 4 | 5 | On this page 6 | 7 | - [Security Methods in the `mongo` Shell](https://docs.mongodb.com/manual/reference/security/#security-methods-in-the-mongo-shell) 8 | - [mongo shell中的安全相关方法]((https://docs.mongodb.com/manual/reference/security/#security-methods-in-the-mongo-shell)) 9 | - [Security Reference Documentation](https://docs.mongodb.com/manual/reference/security/#security-reference-documentation) 10 | - [安全参考文档](https://docs.mongodb.com/manual/reference/security/#security-reference-documentation) 11 | 12 | The following lists the security related methods available in the `mongo` shell as well as additional [security reference material](https://docs.mongodb.com/manual/reference/security/#security-reference-materials). 13 | 14 | 下面列举了mongo shell 中可用的与安全相关的方法,以及其他[安全相关材料](https://docs.mongodb.com/manual/reference/security/#security-reference-materials)。 15 | 16 | ## Security Methods in the mongo Shell 17 | 18 | ## mongo shell中的安全相关方法 19 | 20 | ### User Management and Authentication Methods 21 | 22 | ### 用户管理和认证方法 23 | 24 | | Name | Description | 25 | | :----------------------------------------------------------- | :----------------------------------------------------------- | 26 | | [`db.auth()`](https://docs.mongodb.com/manual/reference/method/db.auth/#db.auth) | Authenticates a user to a database. 向数据库验证用户 | 27 | | [`db.changeUserPassword()`](https://docs.mongodb.com/manual/reference/method/db.changeUserPassword/#db.changeUserPassword) | Changes an existing user’s password.改变用户的密码 | 28 | | [`db.createUser()`](https://docs.mongodb.com/manual/reference/method/db.createUser/#db.createUser) | Creates a new user. 创建一个新用户 | 29 | | [`db.dropUser()`](https://docs.mongodb.com/manual/reference/method/db.dropUser/#db.dropUser) | Removes a single user.删除一个用户 | 30 | | [`db.dropAllUsers()`](https://docs.mongodb.com/manual/reference/method/db.dropAllUsers/#db.dropAllUsers) | Deletes all users associated with a database.删除与数据库相关的用户 | 31 | | [`db.getUser()`](https://docs.mongodb.com/manual/reference/method/db.getUser/#db.getUser) | Returns information about the specified user.返回指定用户信息 | 32 | | [`db.getUsers()`](https://docs.mongodb.com/manual/reference/method/db.getUsers/#db.getUsers) | Returns information about all users associated with a database.返回所有与数据库相关的用户信息 | 33 | | [`db.grantRolesToUser()`](https://docs.mongodb.com/manual/reference/method/db.grantRolesToUser/#db.grantRolesToUser) | Grants a role and its privileges to a user.授予用户角色和角色包含的权限 | 34 | | [`db.removeUser()`](https://docs.mongodb.com/manual/reference/method/db.removeUser/#db.removeUser) | Deprecated. Removes a user from a database.弃用,从数据库删除用户 | 35 | | [`db.revokeRolesFromUser()`](https://docs.mongodb.com/manual/reference/method/db.revokeRolesFromUser/#db.revokeRolesFromUser) | Removes a role from a user.删除用户的角色 | 36 | | [`db.updateUser()`](https://docs.mongodb.com/manual/reference/method/db.updateUser/#db.updateUser) | Updates user data.更新用户数据 | 37 | | [`passwordPrompt()`](https://docs.mongodb.com/manual/reference/method/passwordPrompt/#passwordPrompt) | Prompts for the password as an alternative to specifying passwords directly in various [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell user authentication/management methods.提示输入密码,作为在各种mongo shell用户管理方法中直接指定密码的替代方法 | 38 | 39 | ### Role Management Methods 40 | 41 | ### 角色管理方法 42 | 43 | | Name | Description | 44 | | :----------------------------------------------------------- | :----------------------------------------------------------- | 45 | | [`db.createRole()`](https://docs.mongodb.com/manual/reference/method/db.createRole/#db.createRole) | Creates a role and specifies its privileges.创建一个角色和指定其权限 | 46 | | [`db.dropRole()`](https://docs.mongodb.com/manual/reference/method/db.dropRole/#db.dropRole) | Deletes a user-defined role.删除一个用户自定义角色 | 47 | | [`db.dropAllRoles()`](https://docs.mongodb.com/manual/reference/method/db.dropAllRoles/#db.dropAllRoles) | Deletes all user-defined roles associated with a database.删除与数据库关联的所有用户自定义的角色 | 48 | | [`db.getRole()`](https://docs.mongodb.com/manual/reference/method/db.getRole/#db.getRole) | Returns information for the specified role.返回指定角色的信息 | 49 | | [`db.getRoles()`](https://docs.mongodb.com/manual/reference/method/db.getRoles/#db.getRoles) | Returns information for all the user-defined roles in a database.返回数据库中所有用户自定义角色的信息 | 50 | | [`db.grantPrivilegesToRole()`](https://docs.mongodb.com/manual/reference/method/db.grantPrivilegesToRole/#db.grantPrivilegesToRole) | Assigns privileges to a user-defined role.给指定用户分配权限 | 51 | | [`db.revokePrivilegesFromRole()`](https://docs.mongodb.com/manual/reference/method/db.revokePrivilegesFromRole/#db.revokePrivilegesFromRole) | Removes the specified privileges from a user-defined role.从用户自定义角色中删除指定权限 | 52 | | [`db.grantRolesToRole()`](https://docs.mongodb.com/manual/reference/method/db.grantRolesToRole/#db.grantRolesToRole) | Specifies roles from which a user-defined role inherits privileges.指定用户定义的角色从哪些角色继承特权。 | 53 | | [`db.revokeRolesFromRole()`](https://docs.mongodb.com/manual/reference/method/db.revokeRolesFromRole/#db.revokeRolesFromRole) | Removes inherited roles from a role.从角色中删除继承的角色 | 54 | | [`db.updateRole()`](https://docs.mongodb.com/manual/reference/method/db.updateRole/#db.updateRole) | Updates a user-defined role.更新用户自定义的角色。 | 55 | 56 | 57 | 58 | ## Security Reference Documentation 59 | 60 | ### 安全相关文档 61 | 62 | - [system.roles Collection](https://docs.mongodb.com/manual/reference/system-roles-collection/) 63 | 64 | Describes the content of the collection that stores user-defined roles. 65 | 66 | 描述存储用户自定义角色的集合的内容。 67 | 68 | - [system.users Collection](https://docs.mongodb.com/manual/reference/system-users-collection/) 69 | 70 | Describes the content of the collection that stores users’ credentials and role assignments. 71 | 72 | 描述存储用户凭据和角色分配的集合的内容。 73 | 74 | - [Resource Document](https://docs.mongodb.com/manual/reference/resource-document/) 75 | 76 | Describes the resource document for roles. 77 | 78 | 描述角色的资源文档。 79 | 80 | - [Privilege Actions](https://docs.mongodb.com/manual/reference/privilege-actions/) 81 | 82 | List of the actions available for privileges. 83 | 84 | 可用于权限的操作列表。 85 | 86 | 原文链接:[https://docs.mongodb.com/manual/reference/security/](https://docs.mongodb.com/manual/reference/security/) 87 | 88 | 译者:谢伟成 89 | -------------------------------------------------------------------------------- /09 Security 安全/09-12-01system.rolesCollection system.roles 集合.md: -------------------------------------------------------------------------------- 1 | # system.roles Collection 2 | 3 | # system.roles 集合 4 | 5 | On this page 6 | 7 | - [`system.roles` Schema](https://docs.mongodb.com/manual/reference/system-roles-collection/#system-roles-schema) 8 | - [`system.roles` 集合的Schema](https://docs.mongodb.com/manual/reference/system-roles-collection/#system-roles-schema) 9 | - [Examples](https://docs.mongodb.com/manual/reference/system-roles-collection/#examples) 10 | - [例子](https://docs.mongodb.com/manual/reference/system-roles-collection/#examples) 11 | 12 | The `system.roles` collection in the `admin` database stores the user-defined roles. To create and manage these user-defined roles, MongoDB provides [role management commands](https://docs.mongodb.com/manual/reference/command/#role-management-commands). 13 | 14 | admin数据库中的`system.roles`集合存储用户定义的角色。为了创建和管理这些用户自定义角色,MongoDB提供了[角色管理命令](https://docs.mongodb.com/manual/reference/command/#role-management-commands)。 15 | 16 | ## system.roles Schema 17 | 18 | ## system.roles 集合的Schema 19 | 20 | The documents in the `system.roles` collection have the following schema: 21 | 22 | `system.roles`集合中的文档具有以下的schema: 23 | 24 | copy 25 | 26 | ``` 27 | { 28 | _id: , 29 | role: "", 30 | db: "", 31 | privileges: 32 | [ 33 | { 34 | resource: { }, 35 | actions: [ "", ... ] 36 | }, 37 | ... 38 | ], 39 | roles: 40 | [ 41 | { role: "", db: "" }, 42 | ... 43 | ] 44 | } 45 | ``` 46 | 47 | A `system.roles` document has the following fields: 48 | 49 | 一个`system.roles`文档具有以下字段: 50 | 51 | - `admin.system.roles.``role` 52 | 53 | The [`role`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.role) field is a string that specifies the name of the role. 54 | 55 | 该[`role`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.role)字段是一个字符串,用于指定角色的名称。 56 | 57 | - `admin.system.roles.``db` 58 | 59 | The [`db`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.db) field is a string that specifies the database to which the role belongs. MongoDB uniquely identifies each role by the pairing of its name (i.e. [`role`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.role)) and its database. 60 | 61 | 该[`db`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.db)字段是一个字符串,用于指定角色所属的数据库。MongoDB通过名称(即[`role`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.role))及其数据库的配对来唯一标识每个角色 。 62 | 63 | - `admin.system.roles.``privileges` 64 | 65 | The [`privileges`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.privileges) array contains the privilege documents that define the [privileges](https://docs.mongodb.com/manual/core/authorization/#privileges) for the role. 66 | 67 | 该[`privileges`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.privileges)数组包含权限文件,这些文件定义了角色的[权限](https://docs.mongodb.com/manual/core/authorization/#privileges)。 68 | 69 | A privilege document has the following syntax: 70 | 71 | 权限文档具有以下语法: 72 | 73 | copy 74 | 75 | ```json 76 | { 77 | resource: { }, 78 | actions: [ "", ... ] 79 | } 80 | ``` 81 | 82 | 83 | 84 | `Each privilege document has the following fields:` 85 | 86 | 每个权限文档具有以下字段: 87 | 88 | admin.system.roles.privileges[n].`resource` 89 | 90 | A document that specifies the resources on which the privilege [`actions`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.privileges[n].actions) apply. 91 | 92 | 一个文档,该文档指定权限[操作](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.privileges[n].actions)所应用的资源。 93 | 94 | The document has one of the following form: 95 | 96 | 该文档具有以下格式之一: 97 | 98 | copy 99 | 100 | ```json 101 | { db: , collection: } 102 | ``` 103 | 104 | or 105 | 106 | 或者 107 | 108 | ```json 109 | { cluster : true } 110 | ``` 111 | 112 | 113 | 114 | See [Resource Document](https://docs.mongodb.com/manual/reference/resource-document/#resource-document) for more details. 115 | 116 | 有关更多详细信息,请阅读[资源文档](https://docs.mongodb.com/manual/reference/resource-document/#resource-document)。 117 | 118 | `admin.system.roles.privileges[n].actions` 119 | 120 | An array of actions permitted on the resource. For a list of actions, see [Privilege Actions](https://docs.mongodb.com/manual/reference/privilege-actions/#security-user-actions). 121 | 122 | 资源上允许的一系列操作, 有关操作列表,请参阅[权限操作](https://docs.mongodb.com/manual/reference/privilege-actions/#security-user-actions) 123 | 124 | - `admin.system.roles.roles` 125 | 126 | The [`roles`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.roles) array contains role documents that specify the roles from which this role [inherits](https://docs.mongodb.com/manual/core/authorization/#inheritance) privileges. 127 | 128 | 该[`roles`](https://docs.mongodb.com/manual/reference/system-roles-collection/#admin.system.roles.roles)数组包含角色文档,这些角色文档指定了该角色从中[继承](https://docs.mongodb.com/manual/core/authorization/#inheritance)权限的角色。 129 | 130 | A role document has the following syntax: 131 | 132 | 角色文档具有以下语法: 133 | 134 | copy 135 | 136 | ```json 137 | { role: "", db: "" } 138 | ``` 139 | 140 | A role document has the following fields: 141 | 142 | 角色文档具有以下字段: 143 | 144 | admin.system.roles.roles[n].`role` 145 | 146 | The name of the role. A role can be a [built-in role](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles) provided by MongoDB or a [user-defined role](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles). 147 | 148 | 角色名称。角色可以是 MongoDB 提供的[内置](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles)角色,也可以是[用户定义的角色](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles)。 149 | 150 | `admin.system.roles.roles[n].`db` 151 | 152 | The name of the database where the role is defined. 153 | 154 | 定义角色的数据库的名称。 155 | 156 | ## Examples 157 | 158 | ## 案例 159 | 160 | Consider the following sample documents found in `system.roles` collection of the `admin` database. 161 | 162 | 考虑以下在admin 数据库的 system.roles 中发现的示例文档 163 | 164 | ### A User-Defined Role Specifies Privileges 165 | 166 | ### 用户自定义的角色指定权限 167 | 168 | The following is a sample document for a user-defined role `appUser` defined for the `myApp` database: 169 | 170 | 以下是为 myApp 数据库定义的自定义用户 appUser 的示例文档 171 | 172 | copy 173 | 174 | ``` 175 | { 176 | _id: "myApp.appUser", 177 | role: "appUser", 178 | db: "myApp", 179 | privileges: [ 180 | { resource: { db: "myApp" , collection: "" }, 181 | actions: [ "find", "createCollection", "dbStats", "collStats" ] }, 182 | { resource: { db: "myApp", collection: "logs" }, 183 | actions: [ "insert" ] }, 184 | { resource: { db: "myApp", collection: "data" }, 185 | actions: [ "insert", "update", "remove", "compact" ] }, 186 | { resource: { db: "myApp", collection: "system.js" }, 187 | actions: [ "find" ] }, 188 | ], 189 | roles: [] 190 | } 191 | ``` 192 | 193 | The `privileges` array lists the five privileges that the `appUser` role specifies: 194 | 195 | privileges数组列出了appUser角色指定的五个权限 196 | 197 | - The first privilege permits its actions ( `"find"`, `"createCollection"`, `"dbStats"`, `"collStats"`) on all the collections in the `myApp` database *excluding* its system collections. See [Specify a Database as Resource](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db). 198 | - 第一个权限允许对 myApp 数据库中除 system 集合以外所有集合执行("find"`, `"createCollection"`, `"dbStats"`, `"collStats"`) 操作, 详见 [将数据库指定为操作资源](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db). 199 | - The next two privileges permits *additional* actions on specific collections, `logs` and `data`, in the `myApp` database. See [Specify a Collection of a Database as Resource](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db-collection). 200 | - 后面的两个权限允许对 myApp 数据库中指定的集合 logs 和 data 上执行额外的操作,详见 [指定数据库中的集合作为操作资源](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db-collection). 201 | - The last privilege permits actions on one [system collections](https://docs.mongodb.com/manual/reference/system-collections/) in the `myApp` database. While the first privilege gives database-wide permission for the `find` action, the action does not apply to `myApp`’s system collections. To give access to a system collection, a privilege must explicitly specify the collection. See [Resource Document](https://docs.mongodb.com/manual/reference/resource-document/). 202 | - 最后一个权限允许在 myApp 数据库的 [system 集合](https://docs.mongodb.com/manual/reference/system-collections/) 上操作。虽然第一个权限为查找操作授予了数据库范围,但是不能在 myApp 数据库的 system 集合上操作。为了授予访问 system 集合的权限,权限必须显示指定需要操作的集合。详见[操作资源文档](https://docs.mongodb.com/manual/reference/resource-document/). 203 | 204 | As indicated by the empty `roles` array, `appUser` inherits no additional privileges from other roles. 205 | 206 | 空的roles数组指定 appUser 没有从其他角色继承权限。 207 | 208 | ### User-Defined Role Inherits from Other Roles 209 | 210 | ### 用户自定义的角色继承其他角色权限 211 | 212 | The following is a sample document for a user-defined role `appAdmin` defined for the `myApp` database: The document shows that the `appAdmin` role specifies privileges as well as inherits privileges from other roles: 213 | 214 | 以下示例文档为 myApp 数据库定义了用户自定义角色 appAdmin :文档显示 appAdmin 角色指定了权限,也从其他角色继承了权限。 215 | 216 | copy 217 | 218 | ``` 219 | { 220 | _id: "myApp.appAdmin", 221 | role: "appAdmin", 222 | db: "myApp", 223 | privileges: [ 224 | { 225 | resource: { db: "myApp", collection: "" }, 226 | actions: [ "insert", "dbStats", "collStats", "compact" ] 227 | } 228 | ], 229 | roles: [ 230 | { role: "appUser", db: "myApp" } 231 | ] 232 | } 233 | ``` 234 | 235 | The `privileges` array lists the privileges that the `appAdmin` role specifies. This role has a single privilege that permits its actions ( `"insert"`, `"dbStats"`, `"collStats"`, `"compact"`) on all the collections in the `myApp` database *excluding* its system collections. See [Specify a Database as Resource](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db). 236 | 237 | privileges 数组列举了 appAdmin 角色指定的权限,这个角色有一个权限,允许在除 system 集合外的所有集合上执行 ( `"insert"`, `"dbStats"`, `"collStats"`, `"compact"`)操作。详见[执行数据库作为操作资源](https://docs.mongodb.com/manual/reference/resource-document/#resource-specific-db). 238 | 239 | The `roles` array lists the roles, identified by the role names and databases, from which the role `appAdmin` inherits privileges. 240 | 241 | roles数组列出了由角色名称和数据库标识的角色,角色 appAdmin 从中继承权限。 242 | 243 | 244 | 原文链接:[https://docs.mongodb.com/manual/reference/system-roles-collection/](https://docs.mongodb.com/manual/reference/system-roles-collection/) 245 | 246 | 译者:谢伟成 247 | -------------------------------------------------------------------------------- /09 Security 安全/09-12-02system.usersCollection system.users 集合.md: -------------------------------------------------------------------------------- 1 | # system.users Collection[¶](https://docs.mongodb.com/manual/reference/system-users-collection/#system-users-collection) 2 | 3 | # system.users 集合 4 | 5 | On this page 6 | 7 | - [`system.users` Schema](https://docs.mongodb.com/manual/reference/system-users-collection/#system-users-schema) 8 | - [system.users 集合的Schema](https://docs.mongodb.com/manual/reference/system-users-collection/#system-users-schema) 9 | - [Example](https://docs.mongodb.com/manual/reference/system-users-collection/#example) 10 | - [例子](https://docs.mongodb.com/manual/reference/system-users-collection/#example) 11 | 12 | The `system.users` collection in the `admin` database stores user [authentication](https://docs.mongodb.com/manual/core/authentication/#authentication) and [authorization](https://docs.mongodb.com/manual/core/authorization/#authorization) information. To manage data in this collection, MongoDB provides [user management commands](https://docs.mongodb.com/manual/reference/command/#user-management-commands). 13 | 14 | system.users 集合在 admin 数据库中,保存了用户[身份验证](https://docs.mongodb.com/manual/core/authentication/#authentication)和[授权](https://docs.mongodb.com/manual/core/authorization/#authorization)的信息。为了管理这个集合的数据,MongoDB 提供了用户管理指令。 15 | 16 | ## system.users Schema 17 | 18 | ## system.users 集合的Schema 19 | 20 | The documents in the `system.users` collection have the following schema: 21 | 22 | system.users 集合中的文档具有以下的 schema: 23 | 24 | copy 25 | 26 | ``` 27 | { 28 | _id: , 29 | userId : , // Starting in MongoDB 4.0.9 30 | user: "", 31 | db: "", 32 | credentials: { }, 33 | roles: [ 34 | { role: "", db: "" }, 35 | ... 36 | ], 37 | customData: , 38 | authenticationRestrictions : [ ] // Starting in MongoDB 4.0 39 | } 40 | ``` 41 | 42 | Each `system.users` document has the following fields: 43 | 44 | 每个 system.users 文档都有以下字段: 45 | 46 | - `admin.system.users.``userId` 47 | 48 | A unique identifier for the user assigned to the user upon creation.[`userId`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.userId) is available for users [`created`](https://docs.mongodb.com/manual/reference/method/db.createUser/#db.createUser) in MongoDB 4.0.9 and later.*New in version 4.0.9.* 49 | 50 | 创建时分配给用户的唯一标识符。[userId](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.userId) 适用于在MongoDB 4.0.9 及更高的版本[创建](https://docs.mongodb.com/manual/reference/method/db.createUser/#db.createUser)的用户 51 | 52 | - `admin.system.users.``user` 53 | 54 | The user name. A user exists in the context of a single logical database (see [`admin.system.users.db`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.db)) but can have access on other databases through roles specified in the [`roles`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.roles) array. 55 | 56 | 用户名。用户位于单个逻辑数据库的上下文中(请参考资料[`admin.system.users.db)`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.db),但可以通过[`roles`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.roles)组中指定的角色访问其他数据库。 57 | 58 | - `admin.system.users.``db` 59 | 60 | The [authentication database](https://docs.mongodb.com/manual/core/security-users/#authentication-database) associated with the user. The user’s privileges are not necessarily limited to this database. The user can have privileges in additional databases through the [`roles`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.roles) array. 61 | 62 | 与用户关联的[身份验证数据库](https://docs.mongodb.com/manual/core/security-users/#authentication-database)。用户的权限不一定限于此数据库。用户可以通过该[`roles`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.roles)组在其他数据库中拥有特权。 63 | 64 | - `admin.system.users.``credentials` 65 | 66 | User’s authentication information. For users with externally stored authentication credentials, such as users that use [Kerberos](https://docs.mongodb.com/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/) or x.509 certificates for authentication, the `system.users` document for that user does not contain the [`credentials`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.credentials) field. For [SCRAM](https://docs.mongodb.com/manual/core/security-scram/#authentication-scram) user credentials, the information includes the mechanism, iteration count, and authentication parameters.SEE ALSO[`scramSHA256IterationCount`](https://docs.mongodb.com/manual/reference/parameters/#param.scramSHA256IterationCount)[`scramIterationCount`](https://docs.mongodb.com/manual/reference/parameters/#param.scramIterationCount) 67 | 68 | 用户的身份验证信息。对于具有外部存储的身份验证凭据的用户,例如使用 [Kerberos](https://docs.mongodb.com/manual/tutorial/control-access-to-mongodb-with-kerberos-authentication/) 或x.509证书进行身份验证的`system.users` 用户,该用户的文档不包含该 [`credentials`](https://docs.mongodb.com/manual/reference/system-users-collection/#admin.system.users.credentials)字段。对于 [SCRAM](https://docs.mongodb.com/manual/core/security-scram/#authentication-scram)用户凭据,该信息包括机制,迭代计数和身份验证参数。 69 | 70 | 也可以看看 71 | 72 | - [`scramSHA256IterationCount`](https://docs.mongodb.com/manual/reference/parameters/#param.scramSHA256IterationCount) 73 | - [`scramIterationCount`](https://docs.mongodb.com/manual/reference/parameters/#param.scramIterationCount) 74 | 75 | - `admin.system.users.``roles` 76 | 77 | An array of roles granted to the user. The array contains both [built-in roles](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles) and [user-defined role](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles). 78 | 79 | 授予用户的一系列角色。该组包含 [内置角色](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles)和[用户定义角色](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles)。 80 | 81 | A role document has the following syntax: 82 | 83 | 角色文档具有以下语法: 84 | 85 | copy 86 | 87 | ```js 88 | { role: "", db: "" } 89 | ``` 90 | 91 | A role document has the following fields: 92 | 93 | 角色文档有以下字段 94 | 95 | `admin.system.users.roles[n].``role 96 | 97 | ​ The name of a role. A role can be a [built-in role](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles) provided by MongoDB or a [custom user-defined role](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles). 98 | 99 | ​ 角色名称。角色可以是 MongoDB 提供的[内置](https://docs.mongodb.com/manual/reference/built-in-roles/#built-in-roles)角色,也可以是[用户自定义角色](https://docs.mongodb.com/manual/core/security-user-defined-roles/#user-defined-roles)。 100 | 101 | `admin.system.users.roles[n].``db` 102 | 103 | ​ The name of the database where role is defined. 104 | 105 | ​ 定义角色的数据库的名称。 106 | 107 | When specifying a role using the [role management](https://docs.mongodb.com/manual/reference/command/#role-management-commands) or [user management](https://docs.mongodb.com/manual/reference/command/#user-management-commands) commands, you can specify the role name alone (e.g. `"readWrite"`) if the role that exists on the database on which the command is run. 108 | 109 | 使用[角色管理](https://docs.mongodb.com/manual/reference/command/#role-management-commands)或[用户管理](https://docs.mongodb.com/manual/reference/command/#user-management-commands)命令指定`"readWrite"`角色时,如果运行命令的数据库中存在该角色,则可以单独指定角色名称(例如“ readWrite”)。 110 | 111 | - `admin.system.users.``customData` 112 | 113 | Optional custom information about the user. 114 | 115 | 有关用户的可选自定义信息。 116 | 117 | - `admin.system.users.``authenticationRestrictions` 118 | 119 | An array of authentication restrictions the server enforces for the user. The array containsa list of IP addresses and CIDR ranges from which the user is allowed to connect to the server or from which the server can accept users.*New in version 4.0.* 120 | 121 | 服务器为用户强制执行的一系列身份验证限制。该数组包含 IP 地址和 CIDR 范围的列表,允许用户从中连接到服务器或服务器可以从中接受用户。 122 | 123 | 版本4.0中的新功能。 124 | 125 | ## Example 126 | 127 | Consider the following document in the `system.users` collection: 128 | 129 | 考虑`system.users`集合中的以下文档: 130 | 131 | copy 132 | 133 | ``` 134 | { 135 | "_id" : "home.Kari", 136 | "userId" : UUID("ec1eced7-055a-4ca8-8737-60dd02c52793"), // Available starting in MongoDB 4.0.9 137 | "user" : "Kari", 138 | "db" : "home", 139 | "credentials" : { 140 | "SCRAM-SHA-1" : { 141 | "iterationCount" : 10000, 142 | "salt" : "S/xM2yXFosynbCu4GzFDgQ==", 143 | "storedKey" : "Ist4cgpEd1vTbnRnQLdobgmOsBA=", 144 | "serverKey" : "e/0DyzS6GPboAA2YNBkGYm87+cg=" 145 | }, 146 | "SCRAM-SHA-256" : { 147 | "iterationCount" : 15000, 148 | "salt" : "p1G+fZadAeYAbECN8F/6TMzXGYWBaZ3DtWM0ig==", 149 | "storedKey" : "LEgLOqZQmkGhd0owm/+6V7VdJUYJcXBhPUvi9z+GBfk=", 150 | "serverKey" : "JKfnkVv9iXwxyc8JaapKVwLPy6SfnmB8gMb1Pr15T+s=" 151 | } 152 | }, 153 | "authenticationRestrictions" : [ // Available starting in MongoDB 4.0 154 | { "clientSource" : [ "69.89.31.226" ], "serverAddress" : [ "172.16.254.1" ] } 155 | ], 156 | "customData" : { 157 | "zipCode" : "64157" 158 | }, 159 | "roles" : [ 160 | { 161 | "role" : "read", 162 | "db" : "home" 163 | }, 164 | { 165 | "role" : "readWrite", 166 | "db" : "test" 167 | } 168 | ] 169 | } 170 | ``` 171 | 172 | The document shows that a user `Kari`’s authentication database is the `home` database. `Kari` has the [`read`](https://docs.mongodb.com/manual/reference/built-in-roles/#read) role in the `home` database, the [`readWrite`](https://docs.mongodb.com/manual/reference/built-in-roles/#readWrite) role in the `test` database. 173 | 174 | 该文档显示用户`Kari`的身份验证数据库是 home`数据库。在数据库中`Kari 具有 [read](https://docs.mongodb.com/manual/reference/built-in-roles/#read) 角色,在 test 数据库中具有[`readWrite`](https://docs.mongodb.com/manual/reference/built-in-roles/#readWrite)角色 。 175 | 176 | 177 | 原文链接:[https://docs.mongodb.com/manual/reference/system-users-collection/](https://docs.mongodb.com/manual/reference/system-users-collection/) 178 | 179 | 译者:谢伟成 180 | -------------------------------------------------------------------------------- /09 Security 安全/09-12-03Resource Document 资源文档.md: -------------------------------------------------------------------------------- 1 | # Resource Document 2 | 3 | # 资源文档 4 | 5 | On this page 6 | 7 | - [Database and/or Collection Resource](https://docs.mongodb.com/manual/reference/resource-document/#database-and-or-collection-resource) 8 | - [数据库和/或集合资源](https://docs.mongodb.com/manual/reference/resource-document/#database-and-or-collection-resource) 9 | - [Cluster Resource](https://docs.mongodb.com/manual/reference/resource-document/#cluster-resource) 10 | - [集群资源](https://docs.mongodb.com/manual/reference/resource-document/#cluster-resource) 11 | - [`anyResource`](https://docs.mongodb.com/manual/reference/resource-document/#anyresource) 12 | - [`anyResource`](https://docs.mongodb.com/manual/reference/resource-document/#anyresource) 13 | 14 | The resource document specifies the resources upon which a privilege permits `actions`. 15 | 16 | 资源文档指定了权限所允许操作的资源。 17 | 18 | ## Database and/or Collection Resource 19 | 20 | ## 数据库和/或集合资源 21 | 22 | To specify databases and/or collections, use the following syntax: 23 | 24 | 使用以下语法指定数据库和/或者集合: 25 | 26 | copy 27 | 28 | ```js 29 | { db: , collection: } 30 | ``` 31 | 32 | 33 | 34 | ### Specify a Collection of a Database as Resource 35 | 36 | ### 指定一个数据库中的集合作为操作资源 37 | 38 | If the resource document species both the `db` and `collection` fields as non-empty strings, the resource is the specified collection in the specified database. For example, the following document specifies a resource of the `inventory` collection in the `products` database: 39 | 40 | 如果资源文档同时指定了`db`和`collection`字段为非空字符串,操作资源就是该指定数据库中的指定集合。例如,下面的文档指定了`products`数据库中的`inventory`集合。 41 | 42 | copy 43 | 44 | ``` 45 | { db: "products", collection: "inventory" } 46 | ``` 47 | 48 | For a user-defined role scoped for a non-`admin` database, the resource specification for its privileges must specify the same database as the role. User-defined roles scoped for the `admin` database can specify other databases. 49 | 50 | 非`admin`数据库范围内的用户自定义角色,为其权限指定操作资源时必须指定与该角色相同的数据库。`admin`数据库范围内定义的角色可以指定其他其他数据库为操作资源。 51 | 52 | ### Specify a Database as Resource 53 | 54 | ### 指定一个数据库为资源 55 | 56 | If only the `collection` field is an empty string (`""`), the resource is the specified database, excluding the [system collections](https://docs.mongodb.com/manual/reference/system-collections/). For example, the following resource document specifies the resource of the `test` database, excluding the system collections: 57 | 58 | 如果仅`collection`字段为空字符串(`""`),操作资源就是该指定的数据库,但`system`集合除外。例如,下面的资源文档指定了操作资源为`test`数据库,但`system`集合除外。 59 | 60 | copy 61 | 62 | ``` 63 | { db: "test", collection: "" } 64 | ``` 65 | 66 | For a user-defined role scoped for a non-`admin` database, the resource specification for its privileges must specify the same database as the role. User-defined roles scoped for the `admin` database can specify other databases. 67 | 68 | 非`admin`数据库范围内的用户自定义角色,为其权限指定操作资源时必须指定与该角色相同的数据库。`admin`数据库范围内定义的角色可以指定其他数据库为操作资源。 69 | 70 | NOTE 71 | 72 | When you specify a database as the resource, system collections are excluded, unless you name them explicitly, as in the following: 73 | 74 | 当你指定一个数据库作为操作资源时,`system`集合是不包括在内的,除非像下面这样明确指定: 75 | 76 | copy 77 | 78 | ``` 79 | { db: "test", collection: "system.js" } 80 | ``` 81 | 82 | System collections include but are not limited to the following: 83 | 84 | system集合包括但是不限于以下几项: 85 | 86 | - [`.system.profile`](https://docs.mongodb.com/manual/reference/system-collections/#.system.profile) 87 | - [`.system.js`](https://docs.mongodb.com/manual/reference/system-collections/#.system.js) 88 | - [system.users Collection](https://docs.mongodb.com/manual/reference/system-users-collection/) in the `admin` database 89 | - `admin`数据库中的[system.users](https://docs.mongodb.com/manual/reference/system-users-collection/)集合 90 | - [system.roles Collection](https://docs.mongodb.com/manual/reference/system-roles-collection/) in the `admin` database 91 | - `admin`数据库中的[system.roles](https://docs.mongodb.com/manual/reference/system-roles-collection/)集合 92 | 93 | 94 | 95 | ### Specify Collections Across Databases as Resource 96 | 97 | ### 通过数据库指定集合作为操作资源 98 | 99 | If only the `db` field is an empty string (`""`), the resource is all collections with the specified name across all databases. For example, the following document specifies the resource of all the `accounts` collections across all the databases: 100 | 101 | 如果`db`字段是空字符串(`""`),那么操作资源则是所有数据库中具有指定名称的集合。例如,以下文档指定了所有数据库中`accounts`集合的资源: 102 | 103 | copy 104 | 105 | ``` 106 | { db: "", collection: "accounts" } 107 | ``` 108 | 109 | For user-defined roles, only roles scoped for the `admin` database can have this resource specification for their privileges. 110 | 111 | 对于用户自定义角色,只有作用于`admin`数据库的角色才能拥有此资源指定的权限。 112 | 113 | ### Specify All Non-System Collections in All Databases 114 | 115 | ### 指定所有数据库中的非 system 集合 116 | 117 | If both the `db` and `collection` fields are empty strings (`""`), the resource is all collections, excluding the [system collections](https://docs.mongodb.com/manual/reference/system-collections/), in all the databases: 118 | 119 | 如果`db`和`collection`两个字段都为空字符串(`""`),那么可操作的资源将是所有数据库中除`system`外的所有集合。 120 | 121 | copy 122 | 123 | ``` 124 | { db: "", collection: "" } 125 | ``` 126 | 127 | For user-defined roles, only roles scoped for the `admin` database can have this resource specification for their privileges. 128 | 129 | 对于用户自定义角色,只有作用于`admin`数据库的角色才能拥有此资源指定的权限。 130 | 131 | ## Cluster Resource 132 | 133 | ## 集群资源 134 | 135 | To specify the cluster as the resource, use the following syntax: 136 | 137 | 要将群集指定为资源,请使用以下语法: 138 | 139 | copy 140 | 141 | ``` 142 | { cluster : true } 143 | ``` 144 | 145 | Use the `cluster` resource for actions that affect the state of the system rather than act on specific set of databases or collections. Examples of such actions are `shutdown`, `replSetReconfig`, and `addShard`. For example, the following document grants the action `shutdown` on the `cluster`. 146 | 147 | 使用集群作为 actions 的操作资源,而不是对特定的数据库或集合进行操作,这样的操作会影响系统状态。 此类操作的示例包括“关机”,“ 副本集重新配置”和“添加分片”。 例如,以下文档授予“集群”上的“关机”动作。 148 | `cluster`资源是用来执行那些影响系统状态的操作,而不是用来对特定的数据库或集合执行操作。此类操作的示例包括`shutdown`、`replSetReconfig`和`addShard`。例如,以下文档会将`shutdown`操作赋予`cluster`。 149 | 150 | copy 151 | 152 | ``` 153 | { resource: { cluster : true }, actions: [ "shutdown" ] } 154 | ``` 155 | 156 | For user-defined roles, only roles scoped for the `admin` database can have this resource specification for their privileges. 157 | 158 | 对于用户自定义角色,只有作用于`admin`数据库的角色才能拥有此资源指定的权限。 159 | 160 | ## `anyResource` 161 | 162 | The internal resource `anyResource` gives access to every resource in the system and is intended for internal use. **Do not** use this resource, other than in exceptional circumstances. The syntax for this resource is `{ anyResource: true }`. 163 | 164 | 内部资源`anyResource`使我们能访问系统中任何资源,它只供内部使用。除特殊情况外,不要使用这个资源。使用这个资源的语法为`{ anyResource: true }`。 165 | 166 | 167 | 原文链接:[https://docs.mongodb.com/manual/reference/resource-document/](https://docs.mongodb.com/manual/reference/resource-document/) 168 | 169 | 译者:谢伟成 170 | -------------------------------------------------------------------------------- /09 Security 安全/09-14 Appendix 附录.md: -------------------------------------------------------------------------------- 1 | - [Appendix A - OpenSSL CA Certificate for Testing](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/) 2 | - [Appendix B - OpenSSL Server Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/) 3 | - [Appendix C - OpenSSL Client Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixC-openssl-client/) 4 | - [附录A-用于测试的 OpenSSL CA 证书](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/) 5 | - [附录B-用于测试的 OpenSSL 服务器证书](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/) 6 | 7 | - [附录C-用于测试的 OpenSSL 客户端证书](https://docs.mongodb.com/manual/appendix/security/appendixC-openssl-client/) 8 | 9 | -------------------------------------------------------------------------------- /09 Security 安全/09-14-01 Appendix A - OpenSSL CA Certificate for Testing.md: -------------------------------------------------------------------------------- 1 | # Appendix A - OpenSSL CA Certificate for Testing 2 | # 附录 A - 用于测试的 OpenSSl CA 证书 3 | DISCLAIMER 4 | 5 | This page is provided for **testing purposes** only and the certificates are for **testing purposes only**. 6 | 7 | The following tutorial provides some guidelines for creating **test** x.509 certificates: 8 | 9 | - Do not use these certificates for production. Instead, follow your security policies. 10 | 11 | - For information on OpenSSL, refer to the official OpenSSL docs. Although this tutorial uses OpenSSL, the material should not be taken as an authoritative reference on OpenSSL. 12 | 13 | 14 | 15 | 免责声明 16 | 17 | 提供此页面仅用于**测试目的**,证书仅用于**测试目的**。 18 | 19 | 以下教程提供了一些有关创建**测试** x.509证书的准则 : 20 | 21 | * 请勿将这些证书用于生产。相反,请遵循您的安全策略。 22 | * 有关 OpenSSL 的信息,请参考官方的 OpenSSL 文档。尽管本教程使用的是 OpenSSL,但不应将本材料当作 OpenSSL 的权威参考。 23 | 24 | ## Procedures 25 | 26 | The following procedures outlines the steps to create a **test** CA PEM file. The procedure creates both the CA PEM file and an intermediate authority certificate and key files to sign server/client **test** certificates. 27 | 28 | ## 程序 29 | 30 | 以下过程概述了创建**测试** CA PEM 文件的步骤。该过程同时创建 CA PEM 文件和中间授权证书以及用于签署服务器/客户端**测试**证书的密钥文件。 31 | 32 | ### A. Create the OpenSSL Configuration File 33 | 34 | 1. Create a configuration file `openssl-test-ca.cnf` with the following content: 35 | 36 | copy 37 | 38 | ``` 39 | # NOT FOR PRODUCTION USE. OpenSSL configuration file for testing. 40 | 41 | # For the CA policy 42 | [ policy_match ] 43 | countryName = match 44 | stateOrProvinceName = match 45 | organizationName = match 46 | organizationalUnitName = optional 47 | commonName = supplied 48 | emailAddress = optional 49 | 50 | [ req ] 51 | default_bits = 4096 52 | default_keyfile = myTestCertificateKey.pem ## The default private key file name. 53 | default_md = sha256 ## Use SHA-256 for Signatures 54 | distinguished_name = req_dn 55 | req_extensions = v3_req 56 | x509_extensions = v3_ca # The extentions to add to the self signed cert 57 | 58 | [ v3_req ] 59 | subjectKeyIdentifier = hash 60 | basicConstraints = CA:FALSE 61 | keyUsage = critical, digitalSignature, keyEncipherment 62 | nsComment = "OpenSSL Generated Certificate for TESTING only. NOT FOR PRODUCTION USE." 63 | extendedKeyUsage = serverAuth, clientAuth 64 | 65 | [ req_dn ] 66 | countryName = Country Name (2 letter code) 67 | countryName_default = 68 | countryName_min = 2 69 | countryName_max = 2 70 | 71 | stateOrProvinceName = State or Province Name (full name) 72 | stateOrProvinceName_default = TestCertificateStateName 73 | stateOrProvinceName_max = 64 74 | 75 | localityName = Locality Name (eg, city) 76 | localityName_default = TestCertificateLocalityName 77 | localityName_max = 64 78 | 79 | organizationName = Organization Name (eg, company) 80 | organizationName_default = TestCertificateOrgName 81 | organizationName_max = 64 82 | 83 | organizationalUnitName = Organizational Unit Name (eg, section) 84 | organizationalUnitName_default = TestCertificateOrgUnitName 85 | organizationalUnitName_max = 64 86 | 87 | commonName = Common Name (eg, YOUR name) 88 | commonName_max = 64 89 | 90 | [ v3_ca ] 91 | # Extensions for a typical CA 92 | 93 | subjectKeyIdentifier=hash 94 | basicConstraints = critical,CA:true 95 | authorityKeyIdentifier=keyid:always,issuer:always 96 | ``` 97 | 98 | 2. *Optional*. You can update the default Distinguished Name (DN) values. 99 | 100 | ### A.创建OpenSSL配置文件 101 | 102 | 1. 创建具有以下内容的配置文件 `openssl-test-ca.cnf`: 103 | 104 | ``` 105 | # NOT FOR PRODUCTION USE. OpenSSL configuration file for testing. 106 | # 不用于生产用途。用于测试的OpenSSL配置文件。 107 | 108 | # For the CA policy 109 | # 对于CA策略 110 | 111 | [ policy_match ] 112 | countryName = match 113 | stateOrProvinceName = match 114 | organizationName = match 115 | organizationalUnitName = optional 116 | commonName = supplied 117 | emailAddress = optional 118 | 119 | [ req ] 120 | default_bits = 4096 121 | default_keyfile = myTestCertificateKey.pem ## The default private key file name. 122 | ## 默认私钥文件名 123 | default_md = sha256 ## Use SHA-256 for Signatures 124 | ## 使用SHA-256签名 125 | distinguished_name = req_dn 126 | req_extensions = v3_req 127 | x509_extensions = v3_ca # The extentions to add to the self signed cert 128 | 129 | [ v3_req ] 130 | subjectKeyIdentifier = hash 131 | basicConstraints = CA:FALSE 132 | keyUsage = critical, digitalSignature, keyEncipherment 133 | nsComment = "OpenSSL Generated Certificate for TESTING only. NOT FOR PRODUCTION USE." 134 | extendedKeyUsage = serverAuth, clientAuth 135 | 136 | [ req_dn ] 137 | countryName = Country Name (2 letter code) 138 | countryName_default = 139 | countryName_min = 2 140 | countryName_max = 2 141 | 142 | stateOrProvinceName = State or Province Name (full name) 143 | stateOrProvinceName_default = TestCertificateStateName 144 | stateOrProvinceName_max = 64 145 | 146 | localityName = Locality Name (eg, city) 147 | localityName_default = TestCertificateLocalityName 148 | localityName_max = 64 149 | 150 | organizationName = Organization Name (eg, company) 151 | organizationName_default = TestCertificateOrgName 152 | organizationName_max = 64 153 | 154 | organizationalUnitName = Organizational Unit Name (eg, section) 155 | organizationalUnitName_default = TestCertificateOrgUnitName 156 | organizationalUnitName_max = 64 157 | 158 | commonName = Common Name (eg, YOUR name) 159 | commonName_max = 64 160 | 161 | [ v3_ca ] 162 | # Extensions for a typical CA 163 | # 典型CA的扩展 164 | subjectKeyIdentifier=hash 165 | basicConstraints = critical,CA:true 166 | authorityKeyIdentifier=keyid:always,issuer:always 167 | ``` 168 | 169 | 2. 可选。您可以更新默认专有名称(DN)值。 170 | 171 | ### B. Generate the Test CA PEM File 172 | 173 | ### B. 生成测试 CA PEM 文件 174 | 175 | 1. Create the **test** CA key file `mongodb-test-ca.key`. 176 | 177 | copy 178 | 179 | ``` 180 | openssl genrsa -out mongodb-test-ca.key 4096 181 | ``` 182 | 183 | TIP 184 | 185 | This private key is used to generate valid certificates for the CA. Although this private key, like all files in this appendix, is intended for **testing** purposes only, you should engage in good security practices and secure this key file. 186 | 187 | 188 | 1. 创建**测试** CA 密钥文件 `mongodb-test-ca.key`。 189 | 190 | 复制 191 | 192 | ``` 193 | openssl genrsa -out mongodb-test-ia.key 4096 194 | ``` 195 | 196 | 提示: 197 | 198 | 此私钥用于为CA生成有效证书。尽管此私钥与本附录中的所有文件一样,仅用于**测试**目的,但您应遵循良好的安全惯例并保护此密钥文件。 199 | 200 | 201 | 2. Create the CA certificate `mongod-test-ca.crt` using the generated key file. When asked for Distinguished Name values, enter the appropriate values for your **test** CA certificate. 202 | 203 | copy 204 | 205 | ``` 206 | openssl req -new -x509 -days 1826 -key mongodb-test-ca.key -out mongodb-test-ca.crt -config openssl-test-ca.cnf 207 | ``` 208 | 2. `mongod-test-ca.crt`使用生成的密钥文件创建CA证书。当要求提供专有名称值时,为您的**测试**CA证书输入适当的值。 209 | 210 | 复制 211 | 212 | ``` 213 | openssl req -new -x509 -days 1826 -key mongodb-test-ca.key -out mongodb-test-ca.crt -config openssl-test-ca.cnf 214 | ``` 215 | 216 | 3. Create the private key for the intermediate certificate. 217 | 218 | copy 219 | 220 | ``` 221 | openssl genrsa -out mongodb-test-ia.key 4096 222 | ``` 223 | 224 | TIP 225 | 226 | This private key is used to generate valid certificates for the intermediate authority. Although this private key, like all files in this appendix, is intended for **testing** purposes only, you should engage in good security practices and secure this key file. 227 | 3. 创建中间证书的私钥 228 | 229 | ``` 230 | openssl genrsa -out mongodb-test-ia.key 4096 231 | ``` 232 | 233 | 提示: 234 | 235 | 此私钥用于为中间机构生成有效的证书。尽管此私钥与本附录中的所有文件一样,仅用于**测试**目的,但您应遵循良好的安全惯例并保护此密钥文件。 236 | 237 | 4. Create the certificate signing request for the intermediate certificate. When asked for Distinguished Name values, enter the appropriate values for your **test** Intermediate Authority certificate. 238 | 239 | copy 240 | 241 | ``` 242 | openssl req -new -key mongodb-test-ia.key -out mongodb-test-ia.csr -config openssl-test-ca.cnf 243 | ``` 244 | 245 | 4. 为中间证书创建证书签名请求。当要求提供专有名称值时,请为您的**测试**中间机构证书输入适当的值。 246 | 247 | ``` 248 | openssl req -new -key mongodb-test-ia.key -out mongodb-test-ia.csr -config openssl-test-ca.cnf 249 | ``` 250 | 251 | 5. Create the intermediate certificate `mongodb-test-ia.crt`. 252 | 253 | copy 254 | 255 | ``` 256 | openssl x509 -sha256 -req -days 730 -in mongodb-test-ia.csr -CA mongodb-test-ca.crt -CAkey mongodb-test-ca.key -set_serial 01 -out mongodb-test-ia.crt -extfile openssl-test-ca.cnf -extensions v3_ca 257 | ``` 258 | 259 | 5. 创建中间证书`mongodb-test-ia.crt`。 260 | 261 | 复制 262 | 263 | ``` 264 | openssl x509 -sha256 -req -days 730 -in mongodb-test-ia.csr -CA mongodb-test-ca.crt -CAkey mongodb-test-ca.key -set_serial 01 -out mongodb-test-ia.crt -extfile openssl-test-ca.cnf -extensions v3_ca 265 | ``` 266 | 267 | 268 | 6. Create the **test** CA PEM file from the **test** CA certificate `mongod-test-ca.crt` and **test** intermediate certificate `mongodb-test-ia.crt`. 269 | 270 | copy 271 | 272 | ``` 273 | cat mongodb-test-ca.crt mongodb-test-ia.crt > test-ca.pem 274 | ``` 275 | 276 | You can use the **test** PEM file when configuring [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod), [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos), or [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) for TLS/SSL **testing**. 277 | 278 | You can use the **test** intermediate authority to sign the **test** certificates for both the server(s) and client(s). A single authority must issue the certificates for both the client and the server. 279 | 280 | 6. 从测试的 CA 证书 `mongod-test-ca.crt` 和测试的中间证书 `mongodb-test-ia.crt` 创建测试的 CA PEM 文件。 281 | 282 | 你可以使用测试的 PEM 文件为 TLS/SSL 测试配置[`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod), [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos)或者[`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo)。 283 | 284 | 您可以使用**测试**中间权限来为服务器和客户端签署**测试**证书。单个机构必须为客户端和服务器都颁发证书。 285 | 286 | SEE ALSO 287 | 288 | - [Appendix B - OpenSSL Server Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/#appendix-server-certificate) 289 | - [Appendix C - OpenSSL Client Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixC-openssl-client/#appendix-client-certificate) 290 | 291 | 也可以看看 292 | 293 | * [附录B-用于测试的OpenSSL服务器证书](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/#appendix-server-certificate) 294 | 295 | - [附录C-用于测试的OpenSSL客户端证书](https://docs.mongodb.com/manual/appendix/security/appendixC-openssl-client/#appendix-client-certificate) 296 | -------------------------------------------------------------------------------- /09 Security 安全/09-14-03 Appendix C - OpenSSL Client Certificates for Testing.md: -------------------------------------------------------------------------------- 1 | # Appendix C - OpenSSL Client Certificates for Testing 2 | # 附录C - 用于测试的OpenSSL客户端证书 3 | 4 | DISCLAIMER 5 | 6 | 声明 7 | 8 | This page is provided for **testing purposes** only and the certificates are for **testing purposes only**. 9 | 10 | 此页仅用于**测试目的**;证书仅用于**测试目的**。 11 | 12 | The following tutorial provides some basic steps for creating **test** x.509 certificates. 13 | 14 | 以下教程提供了创建**测试**x.509证书的一些基本步骤。 15 | 16 | - Do not use these certificates for production. Instead, follow your security policies. 17 | - 请勿将这些证书用于生产环境。相反,请遵循您的安全策略。 18 | - For information on OpenSSL, refer to the official OpenSSL docs. Although this tutorial uses OpenSSL, the material should not be taken as an authoritative reference on OpenSSL. 19 | - 有关OpenSSL的信息,请参考官方的OpenSSL文档。尽管本教程使用了OpenSSL,但不应将其视为OpenSSL的权威参考。 20 | 21 | ## Prerequisite 22 | ## 前提条件 23 | 24 | The procedure outlined on this page uses the **test** intermediate authority certificate and key `mongodb-test-ia.crt` and `mongodb-test-ia.key` created in [Appendix A - OpenSSL CA Certificate for Testing](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/). 25 | 26 | 此页面上描述的过程使用了**测试**中间权限证书及在[附录A-用于测试的OpenSSL CA证书](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/)中创建的密钥`mongodb-test-ia.crt`和`mongodb-test-ia.key`。 27 | 28 | ## Procedure 29 | ## 过程 30 | The following procedure outlines the steps to create **test** certificates for MongoDB clients. For steps to create **test** certificates for MongoDB servers, see [Appendix B - OpenSSL Server Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/). 31 | 32 | 以下过程概述了为MongoDB客户端创建测试证书的步骤。有关为MongoDB服务器创建测试证书的步骤,请参阅[附录B - 用于测试的OpenSSL服务器证书](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/) 33 | 34 | ### A. Create the OpenSSL Configuration File 35 | ### A. 创建OpenSSL配置文件 36 | 37 | 1. Create a **test** configuration file `openssl-test-client.cnf` for your client with the following content: 38 | 1. 用下面的内容为你的客户端创建一个**测试**配置文件`openssl-test-client.cnf`: 39 | 40 | ``` 41 | # NOT FOR PRODUCTION USE. OpenSSL configuration file for testing. 42 | 43 | [ req ] 44 | default_bits = 4096 45 | default_keyfile = myTestClientCertificateKey.pem ## The default private key file name. 46 | default_md = sha256 47 | distinguished_name = req_dn 48 | req_extensions = v3_req 49 | 50 | 51 | [ v3_req ] 52 | subjectKeyIdentifier = hash 53 | basicConstraints = CA:FALSE 54 | keyUsage = critical, digitalSignature, keyEncipherment 55 | nsComment = "OpenSSL Generated Certificate for TESTING only. NOT FOR PRODUCTION USE." 56 | extendedKeyUsage = serverAuth, clientAuth 57 | 58 | 59 | [ req_dn ] 60 | countryName = Country Name (2 letter code) 61 | countryName_default = 62 | countryName_min = 2 63 | countryName_max = 2 64 | 65 | stateOrProvinceName = State or Province Name (full name) 66 | stateOrProvinceName_default = TestClientCertificateState 67 | stateOrProvinceName_max = 64 68 | 69 | localityName = Locality Name (eg, city) 70 | localityName_default = TestClientCertificateLocality 71 | localityName_max = 64 72 | 73 | organizationName = Organization Name (eg, company) 74 | organizationName_default = TestClientCertificateOrg 75 | organizationName_max = 64 76 | 77 | organizationalUnitName = Organizational Unit Name (eg, section) 78 | organizationalUnitName_default = TestClientCertificateOrgUnit 79 | organizationalUnitName_max = 64 80 | commonName = Common Name (eg, YOUR name) 81 | commonName_max = 64 82 | ``` 83 | 84 | 85 | 2. *Optional*. You can update the default Distinguished Name (DN) values. Ensure that client certificates differ from server certificates with regards to at least one of the following attributes: Organization (`O`), the Organizational Unit (`OU`) or the Domain Component (`DC`). 86 | 2. *可选*。您可以更新默认专有名称(DN)值。确保客户端证书与服务器证书在以下至少一项属性上有所不同:组织(`O`),组织单位(`OU`)或域组件(`DC`)。 87 | 88 | ### B. Generate the Test PEM File for Client 89 | 90 | ### B. 为客户端创建测试的PEM文件 91 | 92 | 1. Create the **test** key file `mongodb-test-client.key`. 93 | 1. 创建测试密钥文件`mongodb-test-client.key`。 94 | 95 | ``` 96 | openssl genrsa -out mongodb-test-client.key 4096 97 | ``` 98 | 99 | 2. Create the **test** certificate signing request `mongodb-test-client.csr`. When asked for Distinguished Name values, enter the appropriate values for your **test** certificate: 100 | 2. 创建测试的认证签名文件`mongodb-test-client.csr`。当要求提供专有名称值时,为你的测试证书输入合适的值。 101 | 102 | IMPORTANT 103 | 104 | 重要 105 | 106 | The client certificate subject must differ to a server certificate subject with regards to at least one of the following attributes: Organization (O), the Organizational Unit (OU) or the Domain Component (DC). 107 | 108 | 客户端证书主题必须与服务器证书主题在以下属性中至少有一项要不同:组织(`O`),组织单位(`OU`)或域组件(`DC`)。 109 | 110 | ``` 111 | openssl req -new -key mongodb-test-client.key -out mongodb-test-client.csr -config openssl-test-client.cnf 112 | ``` 113 | 114 | 3. Create the **test** client certificate `mongodb-test-client.crt`. 115 | 3. 创建测试客户端证书`mongodb-test-client.crt`。 116 | 117 | ``` 118 | openssl x509 -sha256 -req -days 365 -in mongodb-test-client.csr -CA mongodb-test-ia.crt -CAkey mongodb-test-ia.key -CAcreateserial -out mongodb-test-client.crt -extfile openssl-test-client.cnf -extensions v3_req 119 | ``` 120 | 121 | 4. Create the **test** PEM file for the client. 122 | 4. 为客户端创建测试的PEM文件。 123 | 124 | ``` 125 | cat mongodb-test-client.crt mongodb-test-client.key > test-client.pem 126 | ``` 127 | 128 | You can use the **test** PEM file to configure the [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell for TLS/SSL **testing**. For example, to connect to a [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) or a [`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos): 129 | 130 | 你可以使用**测试**的PEM文件为TLS/SSL测试配置mongo shell。例如,连接一个[`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod)或者[`mongos`](https://docs.mongodb.com/manual/reference/program/mongos/#bin.mongos): 131 | 132 | **For MongoDB 4.2 or greater**, include the following options for the client: 133 | 134 | **对于MongoDB 4.2或更高版本**,在客户端中包含以下选项: 135 | 136 | ``` 137 | mongo --tls --host --tlsCertificateKeyFile test-client.pem --tlsCAFile test-ca.pem 138 | ``` 139 | 140 | **For MongoDB 4.0 and earlier**, include the following options for the client: 141 | 142 | **对于MongoDB 4.0或更早版本**,在客户端中包含以下选项: 143 | 144 | ``` 145 | mongo --ssl --host --sslPEMKeyFile test-client.pem --sslCAFile test-ca.pem 146 | ``` 147 | 148 | ### On macOS 149 | 150 | ### 在macOS系统中 151 | 152 | If you are **testing** with Keychain Access to manage certificates, create a PKCS 12 file to add to Keychain Access instead of a PEM file: 153 | 154 | 如果您使用Keychain Access管理证书,创建一个pkcs-12而不是PEM文件添加到Keychain Access中: 155 | 156 | ``` 157 | openssl pkcs12 -export -out test-client.pfx -inkey mongodb-test-client.key -in mongodb-test-client.crt -certfile mongodb-test-ia.crt 158 | ``` 159 | 160 | Once added to Keychain Access, instead of specifying the Certificate Key file, you can use the [`--tlsCertificateSelector`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-tlscertificateselector) to specify the certificate to use. If the CA file is also in Keychain Access, you can omit `--tlsCAFile` as well as in the following example: 161 | 162 | 将其添加到Keychain Access后,您无需指定证书密钥文件,就可以使用[`--tlsCertificateSelector`](https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-tlscertificateselector)来指定要使用的证书。如果CA文件也在Keychain Access中,也可以省略`--tlsCAFile`。 163 | 164 | **For MongoDB 4.2 or greater** 165 | **对于MongoDB 4.2或更高版本** 166 | 167 | ``` 168 | mongo --tls --tlsCertificateSelector subject="" 169 | ``` 170 | 171 | Although still available, [`--ssl`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-ssl) and [`--sslCertificateSelector`](https://docs.mongodb.com/manual/reference/program/mongo/#cmdoption-mongo-sslcertificateselector) are [deprecated as of MongoDB 4.2](https://docs.mongodb.com/manual/release-notes/4.2/#tls). 172 | 173 | 虽然仍然可以使用,[`--sslMode`](https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-sslmode)和[`--sslCertificateSelector`](https://docs.mongodb.com/manual/reference/program/mongod/#cmdoption-mongod-sslcertificateselector)在[MongoDB 4.2中已废弃](https://docs.mongodb.com/manual/release-notes/4.2/#tls)。 174 | 175 | **For MongoDB 4.0 and earlier** 176 | **对于MongoDB 4.0及更早版本** 177 | 178 | ``` 179 | mongo --ssl --sslCertificateSelector subject="" 180 | ``` 181 | 182 | For adding certificates to Keychain Access, refer to your official documentation for Keychain Access. 183 | 184 | 要向Keychain Access添加证书,请参阅Keychain Access的官方文档。 185 | 186 | ``` 187 | mongod --tlsMode requireTLS --tlsCertificateSelector subject="" 188 | ``` 189 | 190 | SEE ALSO 191 | 192 | - [Appendix A - OpenSSL CA Certificate for Testing](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/#appendix-ca-certificate) 193 | - [Appendix B - OpenSSL Server Certificates for Testing](https://docs.mongodb.com/manual/appendix/security/appendixB-openssl-server/#appendix-server-certificate) 194 | - [Client x.509 Certificate](https://docs.mongodb.com/manual/tutorial/configure-x509-client-authentication/#x509-client-authentication) 195 | 196 | 另请查阅 197 | 198 | - [附录A - 用于测试的OpenSSL CA证书](https://docs.mongodb.com/manual/appendix/security/appendixA-openssl-ca/#appendix-ca-certificate) 199 | - [附录C - 用于测试的OpenSSL客户端证书](https://docs.mongodb.com/manual/appendix/security/appendixC-openssl-client/#appendix-client-certificate) 200 | - [成员的x.509证书](https://docs.mongodb.com/manual/tutorial/configure-x509-member-authentication/#x509-member-certificate) 201 | 202 | -------------------------------------------------------------------------------- /12 Sharding 分片/12-04 Hashed Sharding哈希分片.md: -------------------------------------------------------------------------------- 1 | # Hashed Sharding 哈希分片 2 | 3 | Hashed sharding uses a [hashed index](https://docs.mongodb.com/v4.2/core/index-hashed/#index-hashed-index) to partition data across your shared cluster. Hashed indexes compute the hash value of a single field as the index value; this value is used as your shard key. [[1\]](https://docs.mongodb.com/v4.2/core/hashed-sharding/#hashvalue)
哈希分片使用[哈希索引](https://docs.mongodb.com/v4.2/core/index-hashed/#index-hashed-index)来在分片集群中对数据进行划分。哈希索引计算某一个字段的哈希值作为索引值,这个值被用作片键。 4 | 5 | ![Diagram of the hashed based segmentation.](https://docs.mongodb.com/v4.2/_images/sharding-hash-based.bakedsvg.svg) 6 | 7 | Hashed sharding provides more even data distribution across the sharded cluster at the cost of reducing [Targeted Operations vs. Broadcast Operations](https://docs.mongodb.com/v4.2/core/sharded-cluster-query-router/#sharding-query-isolation). Post-hash, documents with “close” shard key values are unlikely to be on the same chunk or shard - the [`mongos`](https://docs.mongodb.com/v4.2/reference/program/mongos/#bin.mongos) is more likely to perform [Broadcast Operations](https://docs.mongodb.com/v4.2/core/sharded-cluster-query-router/#sharding-mongos-broadcast) to fulfill a given ranged query. [`mongos`](https://docs.mongodb.com/v4.2/reference/program/mongos/#bin.mongos) can target queries with equality matches to a single shard.
哈希分片以减少定向操作和增加广播操作为代价,分片集群内的数据分布更加均衡。在哈希之后,拥有比较“接近”的片键的文档将不太可能会分布在相同的数据库或者分片上。mongos更有可能执行广播操作来完成一个给定的范围查询。相对的,mongos可以将等值匹配的查询直接定位到单个分片上。 8 | 9 | > TIP 注意: 10 | > 11 | > MongoDB automatically computes the hashes when resolving queries using hashed indexes. Applications do **not** need to compute hashes.
当使用哈希索引来解析查询时,MongoDB会自动计算哈希值。应用程序**不需要**计算哈希。 12 | 13 | > WARNING 警告 14 | > 15 | > MongoDB `hashed` indexes truncate floating point numbers to 64-bit integers before hashing. For example, a `hashed` index would store the same value for a field that held a value of `2.3`, `2.2`, and `2.9`. To prevent collisions, do not use a `hashed` index for floating point numbers that cannot be reliably converted to 64-bit integers (and then back to floating point). MongoDB `hashed` indexes do not support floating point values larger than 2^53.
MongoDB哈希索引在哈希计算之前会将浮点数截断为64位整数。 例如,哈希索引会将为具有`2.3`、`2.2`和`2.9`的值的字段存储为相同的值。 为了避免冲突,请勿对不能可靠地转换为64位整数(然后再返回到浮点)的浮点数使用哈希索引。 MongoDB哈希索引不支持大于2^53的浮点值。 16 | > 17 | > To see what the hashed value would be for a key, see [`convertShardKeyToHashed()`](https://docs.mongodb.com/v4.2/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed).
18 | > 19 | > 如果想查看一个键的哈希值是什么,请参考`convertShardKeyToHashed()`。 20 | 21 | | [[1\]](https://docs.mongodb.com/v4.2/core/hashed-sharding/#id1) | Starting in version 4.0, the [`mongo`](https://docs.mongodb.com/v4.2/reference/program/mongo/#bin.mongo) shell provides the method [`convertShardKeyToHashed()`](https://docs.mongodb.com/v4.2/reference/method/convertShardKeyToHashed/#convertShardKeyToHashed). This method uses the same hashing function as the hashed index and can be used to see what the hashed value would be for a key. | 22 | | ------------------------------------------------------------ | ------------------------------------------------------------ | 23 | | | 从4.0版开始,mongo shell提供了`convertShardKeyToHashed()`方法。 此方法使用与哈希索引相同的哈希函数,可用于查看键的哈希值。 | 24 | 25 | ## Hashed Sharding Shard Key 哈希分片的片键 26 | 27 | The field you choose as your hashed shard key should have a good [cardinality](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#shard-key-range), or large number of different values. Hashed keys are ideal for shard keys with fields that change [monotonically](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#shard-key-monotonic) like [ObjectId](https://docs.mongodb.com/v4.2/reference/glossary/#term-objectid) values or timestamps. A good example of this is the default `_id` field, assuming it only contains [ObjectID](https://docs.mongodb.com/v4.2/reference/glossary/#term-objectid) values.
您选择作为哈希片键的字段应具有良好的【基数】或者该字段包含大量不同的值。 哈希分片非常适合选取具有像`ObjectId`值或时间戳那样单调更改的字段作为片键。 一个很好的例子是默认的`_id`字段,假设它仅包含`ObjectID`值(而非用户自定义的`_id`)。 28 | 29 | To shard a collection using a hashed shard key, see [Shard a Collection](https://docs.mongodb.com/v4.2/tutorial/deploy-shard-cluster/#deploy-hashed-sharded-cluster-shard-collection).
要使用哈希片键对集合进行分片,请参阅【对集合进行分片】。 30 | 31 | ## Hashed vs Ranged Sharding 哈希分片 VS 范围分片 32 | 33 | Given a collection using a monotonically increasing value `X` as the shard key, using ranged sharding results in a distribution of incoming inserts similar to the following:
给定一个使用单调递增的值`X`作为片键的集合,使用范围分片会导致插入数据的分布类似于下面这样: 34 | 35 | ![Diagram of poor shard key distribution due to monotonically increasing or decreasing shard key](https://docs.mongodb.com/v4.2/_images/sharded-cluster-monotonic-distribution.bakedsvg.svg) 36 | 37 | 38 | 39 | Since the value of `X` is always increasing, the chunk with an upper bound of [maxKey](https://docs.mongodb.com/v4.2/reference/bson-types/) receives the majority incoming writes. This restricts insert operations to the single shard containing this chunk, which reduces or removes the advantage of distributed writes in a sharded cluster.
由于`X`的值始终在增加,因此具有`maxKey`(上限)的数据块将接收大多数传入的写操作。 这将插入操作限制在只能定向到包含此块的单个分片,从而减少或消除了分片集群中分布式写入的优势。 40 | 41 | By using a hashed index on `X`, the distribution of inserts is similar to the following:
通过在`X`上使用哈希索引,插入的分布将类似于下面这样: 42 | 43 | ![Diagram of hashed shard key distribution](https://docs.mongodb.com/v4.2/_images/sharded-cluster-hashed-distribution.bakedsvg.svg) 44 | 45 | Since the data is now distributed more evenly, inserts are efficiently distributed throughout the cluster.
由于现在数据分布更加均匀,因此可以在整个集群中更高效地分布式插入数据。 46 | 47 | ## Shard the Collection 对一个集合进行分片 48 | 49 | Use the [`sh.shardCollection()`](https://docs.mongodb.com/v4.2/reference/method/sh.shardCollection/#sh.shardCollection) method, specifying the full namespace of the collection and the target [hashed index](https://docs.mongodb.com/v4.2/core/index-hashed/) to use as the [shard key](https://docs.mongodb.com/v4.2/reference/glossary/#term-shard-key).
使用`sh.shardCollection()`方法,指定集合的完整命名空间以及作为片键的目标哈希索引。 50 | 51 | ``` 52 | sh.shardCollection( "database.collection", { : "hashed" } ) 53 | ``` 54 | 55 | > IMPORTANT 重要 56 | > 57 | > - Once you shard a collection, the selection of the shard key is immutable; i.e. you cannot select a different shard key for that collection.
一旦对某个集合进行分片后,片键的选择是不可变的。 也就是说,您不能再为该集合选择其他的片键。 58 | > - Starting in MongoDB 4.2, you can update a document’s shard key value unless the shard key field is the immutable `_id` field. For details on updating the shard key, see [Change a Document’s Shard Key Value](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#update-shard-key).Before MongoDB 4.2, a document’s shard key field value is immutable.
从MongoDB 4.2开始,除非片键字段是不可变的`_id`字段,否则您可以更新文档的片键值。 有关更新片键的详细信息,请参阅【更改文档的片键值】。在MongoDB 4.2以前的版本,片键是不可变的。 59 | 60 | ### Shard a Populated Collection 对一个已有数据的集合进行分片 61 | 62 | If you shard a populated collection using a hashed shard key:
如果您使用哈希片键对一个已经包含数据的集合进行分片操作: 63 | 64 | - The sharding operation creates the initial chunk(s) to cover the entire range of the shard key values. The number of chunks created depends on the [configured chunk size](https://docs.mongodb.com/v4.2/core/sharding-data-partitioning/#sharding-chunk-size).
分片操作将创建初始数据块,以覆盖片键值的整个范围。 创建的数据块数取决于【配置的数据块大小】。 65 | - After the initial chunk creation, the balancer migrates these initial chunks across the shards as appropriate as well as manages the chunk distribution going forward.
在初始数据块创建之后,均衡器会在分片上适当地迁移这些初始数据块,并管理后续的数据块分配。 66 | 67 | ### Shard an Empty Collection 对一个空集合进行分片 68 | 69 | If you shard an empty collection using a hashed shard key:
如果您使用哈希片键对一个空集合进行分片操作: 70 | 71 | - With no zones and zone ranges specified for the empty or non-existing collection:
如果没有为空集合或不存在的集合指定区域和区域范围: 72 | 73 | - The sharding operation creates empty chunks to cover the entire range of the shard key values and performs an initial chunk distribution. By default, the operation creates 2 chunks per shard and migrates across the cluster. You can use `numInitialChunks` option to specify a different number of initial chunks. This initial creation and distribution of chunks allows for faster setup of sharding.
分片操作将创建空数据块,以覆盖片键值的整个范围,并执行初始数据块分配。默认情况下,该操作为每个分片创建2个数据块,并在整个集群中迁移。您可以使用`numInitialChunks`选项指定不同数量的初始块。数据块的这种初始创建和分配可以使分片设置更加快速。 74 | - After the initial distribution, the balancer manages the chunk distribution going forward.
初始分配之后,均衡器将管理后续的数据块分配。 75 | 76 | - With zones and zone ranges specified for the empty or a non-existing collection (Available starting in MongoDB 4.0.3),
如果已经为空集合或不存在的集合指定区域和区域范围(从MongoDB4.0.3版本起可用): 77 | 78 | - The sharding operation creates empty chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges. This initial creation and distribution of chunks allows for faster setup of zoned sharding.
分片操作会为定义的区域范围以及所有其他分片创建空数据块,以覆盖片键值的整个范围,并根据区域范围执行初始数据块分配。数据块的这种初始创建和分配可以使分片设置更加快速。 79 | - After the initial distribution, the balancer manages the chunk distribution going forward.
初始分配之后,均衡器将管理后续的数据块分配。 80 | 81 | 82 | 83 | SEE ALSO 另请参考: 84 | 85 | To learn how to deploy a sharded cluster and implement hashed sharding, see [Deploy a Sharded Cluster](https://docs.mongodb.com/v4.2/tutorial/deploy-shard-cluster/#sharding-procedure-setup).
要了解如何部署分片集群和实现哈希分片,请参阅【部署分片集群】。 86 | 87 | 88 | 89 | 原文链接:https://docs.mongodb.com/v4.2/core/hashed-sharding/ 90 | 91 | 译者:刘翔 92 | -------------------------------------------------------------------------------- /12 Sharding 分片/12-05 Ranged Sharding范围分片.md: -------------------------------------------------------------------------------- 1 | # Ranged Sharding 范围分片 2 | 3 | Range-based sharding involves dividing data into contiguous ranges determined by the shard key values. In this model, documents with “close” shard key values are likely to be in the same [chunk](https://docs.mongodb.com/v4.2/reference/glossary/#term-chunk) or [shard](https://docs.mongodb.com/v4.2/reference/glossary/#term-shard). This allows for efficient queries where reads target documents within a contiguous range. However, both read and write performance may decrease with poor shard key selection. See [Shard Key Selection](https://docs.mongodb.com/v4.2/core/ranged-sharding/#sharding-ranged-shard-key).
基于范围的分片会将数据划分为由片键值确定的连续范围。 在此模型中,具有“接近”片键值的文档可能位于相同的块或分片中。 这允许在连续范围内读取目标文档的高效查询。 但是,如果片键选择不佳,则读取和写入性能均可能降低。 请参阅【片键的选择】。 4 | 5 | ![Diagram of the shard key value space segmented into smaller ranges or chunks.](https://docs.mongodb.com/v4.2/_images/sharding-range-based.bakedsvg.svg) 6 | 7 | Range-based sharding is the default sharding methodology if no other options such as those required for [Hashed Sharding](https://docs.mongodb.com/v4.2/core/hashed-sharding/) or [zones](https://docs.mongodb.com/v4.2/core/zone-sharding/#zone-sharding) are configured.
如果未配置任何其他选项(例如`哈希分片`或`区域`所需的其他选项),则基于范围的分片是默认的分片方式。 8 | 9 | ## Shard Key Selection 片键的选择 10 | 11 | Ranged sharding is most efficient when the shard key displays the following traits:
当片键呈现出以下特征时,范围分片更高效: 12 | 13 | - Large [Shard Key Cardinality](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#shard-key-range) 基数大 14 | - Low [Shard Key Frequency](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#shard-key-frequency) 频率低 15 | - Non-[Monotonically Changing Shard Keys](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#shard-key-monotonic) 非单调变更 16 | 17 | The following image illustrates a sharded cluster using the field `X` as the shard key. If the values for `X` have a large range, low frequency, and change at a non-monotonic rate, the distribution of inserts may look similar to the following:
下图说明了使用字段`X`作为片键的分片群集。 如果`X`的值具有大取值范围,低频率以及非单调变化的特征,则插入的分布可能类似于下面这样: 18 | 19 | ![Diagram of good shard key distribution](https://docs.mongodb.com/v4.2/_images/sharded-cluster-ranged-distribution-good.bakedsvg.svg) 20 | 21 | ## Shard a Collection 对一个集合进行分片 22 | 23 | Use the [`sh.shardCollection()`](https://docs.mongodb.com/v4.2/reference/method/sh.shardCollection/#sh.shardCollection) method, specifying the full namespace of the collection and the target [index](https://docs.mongodb.com/v4.2/reference/glossary/#term-index)or [compound index](https://docs.mongodb.com/v4.2/reference/glossary/#term-compound-index) to use as the [shard key](https://docs.mongodb.com/v4.2/reference/glossary/#term-shard-key).
使用`sh.shardCollection()`方法,指定集合的完整命名空间以及作为片键的目标索引或复合索引。 24 | 25 | ``` 26 | sh.shardCollection( "database.collection", { } ) 27 | ``` 28 | 29 | > IMPORTANT 重要 30 | > 31 | > - Once you shard a collection, the selection of the shard key is immutable; i.e. you cannot select a different shard key for that collection.
一旦对某个集合进行分片后,片键的选择是不可变的。 也就是说,您不能再为该集合选择其他片键。 32 | > - Starting in MongoDB 4.2, you can update a document’s shard key value unless the shard key field is the immutable `_id` field. For details on updating the shard key, see [Change a Document’s Shard Key Value](https://docs.mongodb.com/v4.2/core/sharding-shard-key/#update-shard-key).Before MongoDB 4.2, a document’s shard key field value is immutable.
从MongoDB 4.2开始,除非片键字段是不可变的`_id`字段,否则您可以更新文档的片键值。 有关更新片键的详细信息,请参阅【更改文档的片键值】。在MongoDB 4.2以前的版本,片键是不可变的。 33 | 34 | ### Shard a Populated Collection 对一个已有数据的集合进行分片 35 | 36 | If you shard a populated collection:
如果您对一个已经包含数据的集合进行分片操作: 37 | 38 | - The sharding operation creates the initial chunk(s) to cover the entire range of the shard key values. The number of chunks created depends on the [configured chunk size](https://docs.mongodb.com/v4.2/core/sharding-data-partitioning/#sharding-chunk-size).
分片操作将创建初始数据块,以覆盖片键值的整个范围。 创建的数据块数取决于【配置的数据块大小】。 39 | - After the initial chunk creation, the balancer migrates these initial chunks across the shards as appropriate as well as manages the chunk distribution going forward.
在初始数据块创建之后,均衡器会在分片上适当地迁移这些初始数据块,并管理后续的数据块分配。 40 | 41 | ### Shard an Empty Collection 对一个空集合进行分片 42 | 43 | If you shard an empty collection:
如果您对一个空集合进行分片操作: 44 | 45 | - With no zones and zone ranges specified for the empty or non-existing collection:
如果没有为空集合或不存在的集合指定区域和区域范围: 46 | 47 | - The sharding operation creates a single empty chunk to cover the entire range of the shard key values.
分片操作将创建一个空块,以覆盖片键值的整个范围。 48 | - After the initial chunk creation, the balancer migrates the initial chunk across the shards as appropriate as well as manages the chunk distribution going forward.
在创建初始块之后,平衡器将在块之间适当地迁移初始块,并管理后续的块分配。 49 | 50 | - With zones and zone ranges specified for the empty or a non-existing collection (Available starting in MongoDB 4.0.3)
如果已经为空集合或不存在的集合指定区域和区域范围(从MongoDB4.0.3版本起可用): 51 | 52 | - The sharding operation creates empty chunks for the defined zone ranges as well as any additional chunks to cover the entire range of the shard key values and performs an initial chunk distribution based on the zone ranges. This initial creation and distribution of chunks allows for faster setup of zoned sharding.
分片操作会为定义的区域范围以及覆盖该片键值的整个范围的任何其他块创建空数据块,并根据区域范围执行初始数据块分配。数据块的这种初始创建和分配可以使分片设置更加快速。 53 | - After the initial distribution, the balancer manages the chunk distribution going forward.
在初始分配之后,均衡器将管理后续的数据块分配。 54 | 55 | 56 | 57 | SEE ALSO 另请参阅 58 | 59 | To learn how to deploy a sharded cluster and implement ranged sharding, see [Deploy a Sharded Cluster](https://docs.mongodb.com/v4.2/tutorial/deploy-shard-cluster/#sharding-procedure-setup).
要了解如何部署分片集群和实现范围分片,请参阅【部署分片集群】。 60 | 61 | 62 | 63 | 原文链接:https://docs.mongodb.com/v4.2/core/ranged-sharding/ 64 | 65 | 译者:刘翔 66 | -------------------------------------------------------------------------------- /12 Sharding 分片/12-08-02 Split Chunks in a Sharded Cluster 在分片集群中拆分数据块.md: -------------------------------------------------------------------------------- 1 | [Sharding](https://docs.mongodb.com/manual/sharding/) > [Data Partitioning with Chunks](https://docs.mongodb.com/manual/core/sharding-data-partitioning/) > Split Chunks in a Sharded Cluster 2 | 3 | 4 | 5 | # Split Chunks in a Sharded Cluster 6 | 7 | # 在分片集群中拆分数据块 8 | 9 | Normally, MongoDB splits a [chunk](https://docs.mongodb.com/manual/reference/glossary/#term-chunk) after an insert if the chunk exceeds the maximum [chunk size](https://docs.mongodb.com/manual/core/sharding-data-partitioning/#sharding-chunk-size). However, you may want to split chunks manually if:
通常,如果某个数据块超过最大块大小,则MongoDB会在插入后对数据块进行拆分。但是,在以下情况下,您可能需要手动拆分数据块: 10 | 11 | - you have a large amount of data in your cluster and very few [chunks](https://docs.mongodb.com/manual/reference/glossary/#term-chunk), as is the case after deploying a cluster using existing data.
您的集群中有大量数据,并且只有很少的数据块,就像使用现有数据部署集群后的情况一样 12 | - you expect to add a large amount of data that would initially reside in a single chunk or shard. For example, you plan to insert a large amount of data with [shard key](https://docs.mongodb.com/manual/reference/glossary/#term-shard-key) values between `300` and `400`, *but* all values of your shard keys are between `250` and `500` are in a single chunk.
您希望添加大量最初驻留在单个数据块或分片中的数据。例如,您计划插入大量数据,这些数据的分片键值在`300`到`400`之间,但是所有分片键的值在`250`到`500`之间都在一个块中(且落在一个分片上)。 13 | 14 | > NOTE 注意 15 | > 16 | > MongoDB provides the [`mergeChunks`](https://docs.mongodb.com/manual/reference/command/mergeChunks/#dbcmd.mergeChunks) command to combine contiguous chunk ranges into a single chunk. See [Merge Chunks in a Sharded Cluster](https://docs.mongodb.com/manual/tutorial/merge-chunks-in-sharded-cluster/) for more information.
MongoDB提供了`mergeChunks`命令以将连续的块范围合并为一个块。有关更多信息,请参考【在分片群集中合并数据块】。 17 | 18 | The [balancer](https://docs.mongodb.com/manual/reference/glossary/#term-balancer) may migrate recently split chunks to a new shard immediately if the move benefits future insertions. The balancer does not distinguish between chunks split manually and those split automatically by the system.
如果移动有利于接下来的插入,则`平衡器`可以立即将最近拆分的数据块迁移到新的分片上。平衡器不会区分是手动拆分的数据块还是系统自动拆分的数据块。 19 | 20 | > WARNING 警告 21 | > 22 | > Be careful when splitting data in a sharded collection to create new chunks. When you shard a collection that has existing data, MongoDB automatically creates chunks to evenly distribute the collection. To split data effectively in a sharded cluster you must consider the number of documents in a chunk and the average document size to create a uniform chunk size. When chunks have irregular sizes, shards may have an equal number of chunks but have very different data sizes. Avoid creating splits that lead to a collection with differently sized chunks.
在分片集合中拆分数据以创建新数据块时,请务必小心。当你对一个已有数据的集合进行分片操作时,MongoDB会自动创建数据块以均匀分布该集合。为了有效地在分片群集中拆分数据,必须考虑单个数据块中的文档数和平均文档大小才能创建统一的数据块大小。当数据块的大小不规则时,分片间可能具有相同数量的数据块,但它们的数据大小却大不相同。应避免由于创建时的拆分而导致的分片集合具有大小不同的数据块现象。 23 | 24 | Use [`sh.status()`](https://docs.mongodb.com/manual/reference/method/sh.status/#sh.status) to determine the current chunk ranges across the cluster.
使用`sh.status()`来确定当前集群中的数据块范围 25 | 26 | To split chunks manually, use the [`split`](https://docs.mongodb.com/manual/reference/command/split/#dbcmd.split) command with either fields `middle` or `find`. The [`mongo`](https://docs.mongodb.com/manual/reference/program/mongo/#bin.mongo) shell provides the helper methods [`sh.splitFind()`](https://docs.mongodb.com/manual/reference/method/sh.splitFind/#sh.splitFind) and [`sh.splitAt()`](https://docs.mongodb.com/manual/reference/method/sh.splitAt/#sh.splitAt).
想要手动进行数据块的拆分,使用带`middle`或者`find`字段的`split`命令。mongos shell提供了辅助方法`sh.splitFind()`和`sh.splitAt()` 27 | 28 | [`splitFind()`](https://docs.mongodb.com/manual/reference/method/sh.splitFind/#sh.splitFind) splits the chunk that contains the *first* document returned that matches this query into two equally sized chunks. You must specify the full namespace (i.e. “`.`”) of the sharded collection to [`splitFind()`](https://docs.mongodb.com/manual/reference/method/sh.splitFind/#sh.splitFind). The query in [`splitFind()`](https://docs.mongodb.com/manual/reference/method/sh.splitFind/#sh.splitFind) does not need to use the shard key, though it nearly always makes sense to do so.
`splitFind()`将包含与该查询匹配的返回的*第一个*文档的数据块拆分为两个大小相等的数据块。 您必须将分片集合的完整命名空间(即“` <数据库>.<集合>`”)指定给`splitFind()`。 `splitFind()`中的查询可以不使用分片键,尽管这样做几乎总是有意义的(指可以利用到分片键索引)。 29 | 30 | > EXAMPLE 示例 31 | > 32 | > The following command splits the chunk that contains the value of `63109` for the `zipcode` field in the `people` collection of the `records` database:
下面的命令对`records`数据库的`people`集合为包含`zipcode`字段值为`63109`的数据块进行拆分: 33 | > ```json 34 | > sh.splitFind( "records.people", { "zipcode": "63109" } ) 35 | > ``` 36 | 37 | Use [`splitAt()`](https://docs.mongodb.com/manual/reference/method/sh.splitAt/#sh.splitAt) to split a chunk in two, using the queried document as the lower bound in the new chunk: 38 | 使用[`splitAt()`](https://docs.mongodb.com/manual/reference/method/sh.splitAt/#sh.splitAt)将大块一分为二,将查询的文档用作新的块的下限: 39 | 40 | > EXAMPLE 示例 41 | > 42 | > The following command splits the chunk that contains the value of `63109` for the `zipcode` field in the `people` collection of the `records` database.
下面的命令对`records`数据库的`people`集合为包含`zipcode`字段值为`63109`的数据块进行拆分: 43 | > ```json 44 | > sh.splitAt( "records.people", { "zipcode": "63109" } ) 45 | > ``` 46 | 47 | > NOTE 注意 48 | > 49 | > [`splitAt()`](https://docs.mongodb.com/manual/reference/method/sh.splitAt/#sh.splitAt) does not necessarily split the chunk into two equally sized chunks. The split occurs at the location of the document matching the query, regardless of where that document is in the chunk.
`splitAt()`不一定会将数据块平均分为两个大小相等的块。拆分发生在于查询匹配的文档的位置,而不会考虑该文档在整个数据块中的位置。 50 | 51 | SEE ALSO 另请参考 52 | 53 | [Empty Collection](https://docs.mongodb.com/manual/core/sharding-data-partitioning/#initial-chunks-empty-collection)
【空集合】 54 | 55 | 56 | 57 | 原文链接:https://docs.mongodb.com/manual/tutorial/split-chunks-in-sharded-cluster/index.html 58 | 59 | 译者:刘翔 60 | -------------------------------------------------------------------------------- /13 Administration 管理/13-06 Configuration and Maintenance配置和维护.md: -------------------------------------------------------------------------------- 1 | # [Configuration and Maintenance](https://docs.mongodb.com/v4.2/administration/configuration-and-maintenance/#configuration-and-maintenance ) 2 | 3 | ## 配置和维护 4 | 5 | This section describes routine management operations, including updating your MongoDB deployment’s configuration. 6 | 7 | 本节介绍常规管理操作,包括更新MongoDB部署的配置。 8 | 9 | - [Run-time Database Configuration](https://docs.mongodb.com/v4.2/administration/configuration/) 10 | 11 | - [运行时数据库配置](https://docs.mongodb.com/v4.2/administration/configuration/) 12 | 13 | Outlines common MongoDB configurations and examples of best-practice configurations for common use cases. 14 | 15 | 概述了常见的MongoDB配置和常见用例的最佳实践配置的示例。 16 | 17 | - [Upgrade to the Latest Revision of MongoDB](https://docs.mongodb.com/v4.2/tutorial/upgrade-revision/) 18 | 19 | - [升级至MongoDB的最新版本](https://docs.mongodb.com/v4.2/tutorial/upgrade-revision/) 20 | 21 | Introduces the basic process for upgrading a MongoDB deployment between different minor release versions. 22 | 23 | 介绍在不同版本之间升级MongoDB部署的基本过程。 24 | 25 | - [Manage mongod Processes](https://docs.mongodb.com/v4.2/tutorial/manage-mongodb-processes/) 26 | 27 | - [管理mongod进程](https://docs.mongodb.com/v4.2/tutorial/manage-mongodb-processes/) 28 | 29 | Start, configure, and manage running [mongod](https://docs.mongodb.com/v4.2/reference/program/mongod/#bin.mongod) process. 30 | 31 | 启动、配置和管理运行 [mongod](https://docs.mongodb.com/v4.2/reference/program/mongod/#bin.mongod) 进程。 32 | 33 | - [Terminate Running Operations](https://docs.mongodb.com/v4.2/tutorial/terminate-running-operations/) 34 | 35 | - [终止运行操作](https://docs.mongodb.com/v4.2/tutorial/terminate-running-operations/) 36 | 37 | Stop in progress MongoDB client operations using [`db.killOp()`](https://docs.mongodb.com/v4.2/reference/method/db.killOp/#db.killOp) and [`maxTimeMS()`](https://docs.mongodb.com/v4.2/reference/method/cursor.maxTimeMS/#cursor.maxTimeMS). 38 | 39 | 使用[`db.killOp()`](https://docs.mongodb.com/v4.2/reference/method/db.killOp/#db.killOp)和[`maxTimeMS()`](https://docs.mongodb.com/v4.2/reference/method/cursor.maxTimeMS/#cursor.maxTimeMS)停止正在进行的MongoDB客户端操作。 40 | 41 | - [Rotate Log Files](https://docs.mongodb.com/v4.2/tutorial/rotate-log-files/) 42 | 43 | - [轮转日志文件](https://docs.mongodb.com/v4.2/tutorial/rotate-log-files/) 44 | 45 | Archive the current log files and start new ones. 46 | 47 | 归档当前日志文件并启动新的日志文件。 48 | 49 | 50 | 51 | ## 附: 52 | 53 | 运行时数据库配置:https://docs.mongodb.com/v4.2/administration/configuration/ 54 | 55 | 升级至MongoDB的最新版本:https://docs.mongodb.com/v4.2/tutorial/upgrade-revision/ 56 | 57 | 管理mongod进程:https://docs.mongodb.com/v4.2/tutorial/manage-mongodb-processes/ 58 | 59 | 终止运行操作:https://docs.mongodb.com/v4.2/tutorial/terminate-running-operations/ 60 | 61 | 轮转日志文件:https://docs.mongodb.com/v4.2/tutorial/rotate-log-files/ 62 | 63 | 原文链接:https://docs.mongodb.com/v4.2/administration/configuration-and-maintenance/#configuration-and-maintenance 64 | 65 | 66 | 67 | 译者:孔令升 68 | -------------------------------------------------------------------------------- /14 Storage 存储/14-01-01 WiredTiger Storage Engine WiredTiger存储引擎.md: -------------------------------------------------------------------------------- 1 | ## **WiredTiger Storage Engine** 2 | 3 | ## **WiredTiger存储引擎** 4 | 5 | Starting in MongoDB 3.2, the WiredTiger storage engine is the default storage engine. For existing deployments, if you do not specify the --storageEngine or the storage.engine setting, the version 3.2+ mongod instance can automatically determine the storage engine used to create the data files in the --dbpath or storage.dbPath. See Default Storage Engine Change. 6 | 从MongoDB 3.2开始,WiredTiger存储引擎开始作为默认的存储引擎。 对于现有部署,如果未指定参数--storageEngine或storage.engine设置,则版本3.2+ mongod实例可以自动确定用于在--dbpath或storage.dbPath中创建数据文件的存储引擎。 请参阅默认存储引擎配置参数更改文档。 7 | 8 | **Document Level Concurrency 文档级别的并发** 9 | 10 | WiredTiger uses document-level concurrency control for write operations. As a result, multiple clients can modify different documents of a collection at the same time. 11 | WiredTiger使用文档级并发控制进行写操作。 因此,多个客户端可以并发同时修改集合的不同文档。 12 | 13 | For most read and write operations, WiredTiger uses optimistic concurrency control. WiredTiger uses only intent locks at the global, database and collection levels. When the storage engine detects conflicts between two operations, one will incur a write conflict causing MongoDB to transparently retry that operation. 14 | 对于大多数读写操作,WiredTiger使用乐观并发控制模式。 WiredTiger仅在全局、数据库和集合级别使用意向锁。 当存储引擎检测到两个操作之间存在冲突时,将引发写冲突,从而导致MongoDB自动重试该操作。 15 | 16 | Some global operations, typically short lived operations involving multiple databases, still require a global “instance-wide” lock. Some other operations, such as dropping a collection, still require an exclusive database lock. 17 | 一些全局操作(通常是涉及多个数据库的短暂操作)仍然需要全局“实例范围级别的”锁。 其他一些操作(例如删除集合)仍然需要独占数据库锁。 18 | 19 | **Snapshots and Checkpoints 快照与检查点** 20 | 21 | WiredTiger uses MultiVersion Concurrency Control (MVCC). At the start of an operation, WiredTiger provides a point-in-time snapshot of the data to the operation. A snapshot presents a consistent view of the in-memory data. 22 | WiredTiger使用MultiVersion并发控制(MVCC)方式。 在操作开始时,WiredTiger为操作提供数据的时间点快照。 快照提供了内存数据的一致视图。 23 | 24 | When writing to disk, WiredTiger writes all the data in a snapshot to disk in a consistent way across all data files. The now-durable data act as a checkpoint in the data files. The checkpoint ensures that the data files are consistent up to and including the last checkpoint; i.e. checkpoints can act as recovery points. 25 | 写入磁盘时,WiredTiger将所有数据文件中的快照中的所有数据以一致的方式写入磁盘。 现在持久的数据充当数据文件中的检查点。 该检查点可确保数据文件直到最后一个检查点(包括最后一个检查点)都保持一致; 即检查点可以充当恢复点。 26 | 27 | Starting in version 3.6, MongoDB configures WiredTiger to create checkpoints (i.e. write the snapshot data to disk) at intervals of 60 seconds. In earlier versions, MongoDB sets checkpoints to occur in WiredTiger on user data at an interval of 60 seconds or when 2 GB of journal data has been written, whichever occurs first. 28 | 29 | 从3.6版本开始,MongoDB配置WiredTiger以60秒的间隔创建检查点(即将快照数据写入磁盘)。 在早期版本中,MongoDB将检查点设置为在WiredTiger中以60秒的间隔或在写入2GB日志数据时对用户数据进行检查,以先到者为准。 30 | 31 | During the write of a new checkpoint, the previous checkpoint is still valid. As such, even if MongoDB terminates or encounters an error while writing a new checkpoint, upon restart, MongoDB can recover from the last valid checkpoint. 32 | 在写入新检查点期间,先前的检查点仍然有效。 这样,即使MongoDB在写入新检查点时终止或遇到错误,重启后,MongoDB仍可从上一个有效检查点恢复。 33 | 34 | The new checkpoint becomes accessible and permanent when WiredTiger’s metadata table is atomically updated to reference the new checkpoint. Once the new checkpoint is accessible, WiredTiger frees pages from the old checkpoints. 35 | 当WiredTiger的元数据表被原子更新以引用新的检查点时,新的检查点将变为可访问且永久的。 一旦可以访问新的检查点,WiredTiger就会从旧的检查点释放页面。 36 | 37 | Using WiredTiger, even without journaling, MongoDB can recover from the last checkpoint; however, to recover changes made after the last checkpoint, run with journaling. 38 | 使用WiredTiger,即使没有日记,MongoDB也可以从最后一个检查点恢复; 但是,要恢复上一个检查点之后所做的更改,请运行日志功能。 39 | 40 | NOTE 注意 41 | 42 | Starting in MongoDB 4.0, you cannot specify --nojournal option or storage.journal.enabled: false for replica set members that use the WiredTiger storage engine. 43 | 从MongoDB 4.0开始,您不能指定--nojournal选项或storage.journal.enabled:使用WiredTiger存储引擎的副本集成员为false。 44 | 45 | **Journal日志** 46 | 47 | WiredTiger uses a write-ahead log (i.e. journal) in combination with checkpoints to ensure data durability. 48 | WiredTiger将预写日志(即日志)与检查点结合使用以确保数据持久性。 49 | 50 | The WiredTiger journal persists all data modifications between checkpoints. If MongoDB exits between checkpoints, it uses the journal to replay all data modified since the last checkpoint. For information on the frequency with which MongoDB writes the journal data to disk, see Journaling Process. 51 | WiredTiger日记保留检查点之间的所有数据修改。 如果MongoDB在检查点之间退出,它将使用日志重播自上一个检查点以来修改的所有数据。 有关MongoDB将日记数据写入磁盘的频率的信息,请参阅日志处理。 52 | 53 | WiredTiger journal is compressed using the snappy compression library. To specify a different compression algorithm or no compression, use the storage.wiredTiger.engineConfig.journalCompressor setting. For details on changing the journal compressor, see Change WiredTiger Journal Compressor. 54 | WiredTiger日志使用快速压缩库进行压缩。 要指定其他压缩算法或不进行压缩,请使用storage.wiredTiger.engineConfig.journalCompressor设置参数。 有关更改日志压缩器的详细信息,请参阅“更改WiredTiger日志压缩器”文档。 55 | 56 | NOTE 注意 57 | 58 | If a log record less than or equal to 128 bytes (the mininum log record size for WiredTiger), WiredTiger does not compress that record. 59 | 如果日志记录小于或等于128字节(WiredTiger的最小日志记录大小),则WiredTiger不会压缩该记录。 60 | 61 | You can disable journaling for standalone instances by setting storage.journal.enabled to false, which can reduce the overhead of maintaining the journal. For standalone instances, not using the journal means that, when MongoDB exits unexpectedly, you will lose all data modifications prior to the last checkpoint. 62 | 您可以通过将storage.journal.enabled设置为false来禁用独立实例的日志记录,这可以减少维护日志记录的开销。 对于独立实例,不使用日志意味着MongoDB意外退出时,您将丢失最后一个检查点之前的所有数据修改信息。 63 | 64 | NOTE 注意 65 | 66 | Starting in MongoDB 4.0, you cannot specify --nojournal option or storage.journal.enabled: false for replica set members that use the WiredTiger storage engine. 67 | 从MongoDB 4.0开始,您不能指定--nojournal选项或storage.journal.enabled:使用WiredTiger存储引擎的副本集成员为false。 68 | 69 | SEE ALSO 也可以参考 70 | 71 | Journaling with WiredTiger 72 | 使用WiredTiger日志 73 | 74 | **Compression压缩** 75 | 76 | With WiredTiger, MongoDB supports compression for all collections and indexes. Compression minimizes storage use at the expense of additional CPU. 77 | 使用WiredTiger,MongoDB支持对所有集合和索引进行压缩。 压缩可最大程度地减少存储空间的使用量,但会增加CPU的开销。 78 | 79 | By default, WiredTiger uses block compression with the snappy compression library for all collections and prefix compression for all indexes. 80 | 默认情况下,WiredTiger对所有集合使用块压缩和snappy压缩库,对所有索引使用前缀压缩。 81 | 82 | For collections, the following block compression libraries are also available: 83 | 对于集合,还提供以下块压缩库: 84 | 85 | zlib 86 | zstd (Available starting in MongoDB 4.2) 87 | To specify an alternate compression algorithm or no compression, use the storage.wiredTiger.collectionConfig.blockCompressor setting. 88 | zstd(从MongoDB 4.2开始支持) 89 | 要指定替代压缩算法或不压缩,请使用storage.wiredTiger.collectionConfig.blockCompressor参数设置。 90 | 91 | For indexes, to disable prefix compression, use the storage.wiredTiger.indexConfig.prefixCompression setting. 92 | 对于索引,要禁用前缀压缩,请使用storage.wiredTiger.indexConfig.prefixCompression设置。 93 | 94 | Compression settings are also configurable on a per-collection and per-index basis during collection and index creation. See Specify Storage Engine Options and db.collection.createIndex() storageEngine option. 95 | 压缩设置还可以在集合和索引创建期间基于每个集合和每个索引进行配置。 请参见指定存储引擎选项和db.collection.createIndex()storageEngine选项。 96 | 97 | For most workloads, the default compression settings balance storage efficiency and processing requirements. 98 | 对于大多数压缩工作负载,默认压缩设置可以平衡存储效率和处理要求。 99 | 100 | The WiredTiger journal is also compressed by default. For information on journal compression, see Journal. 101 | 默认情况下,WiredTiger日志也被压缩。 有关日志压缩的信息,请参阅日记。 102 | 103 | **Memory Use 内存使用** 104 | 105 | With WiredTiger, MongoDB utilizes both the WiredTiger internal cache and the filesystem cache. 106 | 通过WiredTiger,MongoDB可以利用WiredTiger内部缓存和文件系统缓存。 107 | 108 | Starting in MongoDB 3.4, the default WiredTiger internal cache size is the larger of either: 109 | 从MongoDB 3.4开始,默认的WiredTiger内部缓存大小是以下两者中的较大者: 110 | 111 | 50% of (RAM - 1 GB), or 256 MB. 112 | 50%(RAM-1 GB)或256 MB。 113 | 114 | For example, on a system with a total of 4GB of RAM the WiredTiger cache will use 1.5GB of RAM (0.5 * (4 GB - 1 GB) = 1.5 GB). Conversely, a system with a total of 1.25 GB of RAM will allocate 256 MB to the WiredTiger cache because that is more than half of the total RAM minus one gigabyte (0.5 * (1.25 GB - 1 GB) = 128 MB < 256 MB). 115 | 例如,在总共有4GB RAM的系统上,WiredTiger缓存将使用1.5GB RAM(0.5 *(4 GB-1 GB)= 1.5 GB)。 相反,总内存为1.25 GB的系统将为WiredTiger缓存分配256 MB,因为这是总RAM的一半以上减去一GB(0.5 *(1.25 GB-1 GB)= 128 MB <256 MB) 。 116 | 117 | NOTE 注意 118 | 119 | In some instances, such as when running in a container, the database can have memory constraints that are lower than the total system memory. In such instances, this memory limit, rather than the total system memory, is used as the maximum RAM available. 120 | 在某些情况下,例如在容器中运行时,数据库的内存限制可能低于系统总内存。 在这种情况下,此内存限制而不是系统总内存将用作最大可用RAM。 121 | 122 | To see the memory limit, see hostInfo.system.memLimitMB. 123 | 要查看内存限制,请参阅hostInfo.system.memLimitMB。 124 | 125 | By default, WiredTiger uses Snappy block compression for all collections and prefix compression for all indexes. Compression defaults are configurable at a global level and can also be set on a per-collection and per-index basis during collection and index creation. 126 | 默认情况下,WiredTiger对所有集合使用Snappy块压缩,对所有索引使用前缀压缩。 压缩默认值是可以在全局级别配置的,也可以在收集和索引创建期间基于每个集合和每个索引进行设置。 127 | 128 | Different representations are used for data in the WiredTiger internal cache versus the on-disk format: 129 | WiredTiger内部缓存中的数据与磁盘格式使用不同的表示形式: 130 | 131 | Data in the filesystem cache is the same as the on-disk format, including benefits of any compression for data files. The filesystem cache is used by the operating system to reduce disk I/O. 132 | Indexes loaded in the WiredTiger internal cache have a different data representation to the on-disk format, but can still take advantage of index prefix compression to reduce RAM usage. Index prefix compression deduplicates common prefixes from indexed fields. 133 | Collection data in the WiredTiger internal cache is uncompressed and uses a different representation from the on-disk format. Block compression can provide significant on-disk storage savings, but data must be uncompressed to be manipulated by the server. 134 | Via the filesystem cache, MongoDB automatically uses all free memory that is not used by the WiredTiger cache or by other processes. 135 | 136 | 文件系统缓存中的数据与磁盘上的格式相同,包括对数据文件进行任何压缩的好处。 操作系统使用文件系统缓存来减少磁盘I/O。 137 | 加载到WiredTiger内部缓存中的索引具有与磁盘上格式不同的数据表示形式,但仍可以利用索引前缀压缩来减少RAM使用量。 索引前缀压缩可从索引字段中删除通用前缀。 138 | WiredTiger内部缓存中的集合数据未经压缩,并使用与磁盘格式不同的表示形式。 块压缩可以节省大量的磁盘存储空间,但是必须对数据进行解压缩才能由服务器进行处理。 139 | 通过文件系统缓存,MongoDB自动使用WiredTiger缓存或其他进程未使用的所有可用内存。 140 | 141 | To adjust the size of the WiredTiger internal cache, see storage.wiredTiger.engineConfig.cacheSizeGB and --wiredTigerCacheSizeGB. Avoid increasing the WiredTiger internal cache size above its default value. 142 | 143 | 要调整WiredTiger内部缓存的大小,请参阅storage.wiredTiger.engineConfig.cacheSizeGB和--wiredTigerCacheSizeGB。 避免将WiredTiger内部缓存的大小超过其默认值以上。 144 | 145 | 146 | 147 | 原文链接:https://docs.mongodb.com/manual/core/wiredtiger/ 148 | 149 | 译者:徐雷 150 | 151 | -------------------------------------------------------------------------------- /14 Storage 存储/14-01-02 In-Memory Storage Engine 内存存储引擎.md: -------------------------------------------------------------------------------- 1 | # In-Memory Storage Engine 内存存储引擎 2 | 3 | 4 | 5 | Starting in MongoDB Enterprise version 3.2.6, the in-memory storage engine is part of general availability (GA) in the 64-bit builds. Other than some metadata and diagnostic data, the in-memory storage engine does not maintain any on-disk data, including configuration data, indexes, user credentials, etc. 6 | 7 | 从MongoDB Enterprise 3.2.6开始,In-Memory内存存储引擎是64位版本中通用可用性(GA)的一部分。 除某些元数据和诊断数据外,In-Memory内存存储引擎不维护任何磁盘上的数据,包括配置数据、索引、用户凭据等。 8 | By avoiding disk I/O, the in-memory storage engine allows for more predictable latency of database operations. 9 | 通过避免磁盘I / O,内存中存储引擎使数据库操作的延迟更可预测。 10 | 11 | ## **Specify In-Memory Storage Engine** 12 | ## **指定In-Memory存储引擎** 13 | 14 | 15 | To select the in-memory storage engine, specify: 16 | 要选择in-memory内存存储引擎,配置启动参数即可: 17 | 18 | inMemory for the --storageEngine option, or the storage.engine setting if using a configuration file. 19 | 用于--storageEngine选项设置inMemory;或者如果使用配置文件方式,则为storage.engine设置。 20 | --dbpath, or storage.dbPath if using a configuration file. Although the in-memory storage engine does not write data to the filesystem, it maintains in the 21 | --dbpath small metadata files and diagnostic data as well temporary files for building large indexes. 22 | --dbpath,如果使用配置文件,则为storage.dbPath。 尽管内存存储引擎不会将数据写入文件系统,但它会在--dbpath中维护小型元数据文件和诊断数据以及用于构建大型索引的临时文件。 23 | 24 | For example, from the command line: 25 | 例如,从命令行输入参数命令: 26 | > mongod --storageEngine inMemory --dbpath 27 | 28 | Or, if using the [YAML configuration file format](https://docs.mongodb.com/manual/reference/configuration-options/): 29 | 或者,如果使用[YAML配置文件格式](https://docs.mongodb.com/manual/reference/configuration-options/): 30 | 31 | > storage: 32 | > 33 | > engine: inMemory 34 | > 35 | > dbPath: 36 | 37 | See inMemory Options for configuration options specific to this storage engine. Most mongod configuration options are available for use with in-memory storage engine except for those options that are related to data persistence, such as journaling or encryption at rest configuration. 38 | 请参阅内存选项中有关此存储引擎的配置选项。 除与数据持久性相关的那些选项参数(例如日志记录或静态配置加密)外,大多数mongod配置选项均可用于in-memory内存存储引擎。 39 | > WARNING警告 40 | > The in-memory storage engine does not persist data after process shutdown. 41 | 进程关闭后,内存中存储引擎不会保留数据。 42 | 43 | ## Concurrency 并发 44 | 45 | 46 | The in-memory storage engine uses document-level concurrency control for write operations. As a result, multiple clients can modify different documents of a collection at the same time. 47 | 48 | in-memory内存存储引擎将文档级并发控制用于写入操作。 因此,多个客户端可以同时修改集合的不同文档。 49 | 50 | ## Memory Use 内存使用 51 | 52 | In-memory storage engine requires that all its data (including indexes, oplog if mongod instance is part of a replica set, etc.) must fit into the specified --inMemorySizeGB command-line option or storage.inMemory.engineConfig.inMemorySizeGB setting in the YAML configuration file. 53 | 内存存储引擎要求其所有数据(包括索引,oplog(如果mongod实例是副本集的一部分)等)必须适合指定的--inMemorySizeGB命令行选项或中的storage.inMemory.engineConfig.inMemorySizeGB设置。 YAML配置文件。 54 | 55 | By default, the in-memory storage engine uses 50% of physical RAM minus 1 GB. 56 | 默认情况下,in-memory 内存存储引擎使用50%的(物理RAM减去1GB)。 57 | If a write operation would cause the data to exceed the specified memory size, MongoDB returns with the error: 58 | 如果写操作将导致数据超过指定的内存大小,则MongoDB返回错误: 59 | > "WT_CACHE_FULL: operation would overflow cache" “ WT_CACHE_FULL:操作将溢出缓存” 60 | 61 | To specify a new size, use the storage.inMemory.engineConfig.inMemorySizeGB setting in the YAML configuration file format: 62 | 要指定新大小,请使用YAML配置文件格式的storage.inMemory.engineConfig.inMemorySizeGB设置: 63 | 64 | Or use the command-line option --inMemorySizeGB: 65 | 或使用命令行选项--inMemorySizeGB启动服务: 66 | > mongod --storageEngine inMemory --dbpath --inMemorySizeGB 67 | 68 | ## Durability 持久性 69 | 70 | The in-memory storage engine is non-persistent and does not write data to a persistent storage. Non-persisted data includes application data and system data, such as users, permissions, indexes, replica set configuration, sharded cluster configuration, etc. 71 | 内存中存储引擎是非持久性的,不会将数据写入持久性存储。 非持久数据包括应用程序数据和系统数据,例如用户,权限,索引,副本集配置,分片群集配置等。 72 | 73 | As such, the concept of journal or waiting for data to become durable does not apply to the in-memory storage engine. 74 | 因此,日志或等待数据变得持久的概念不适用于内存中的存储引擎。 75 | 76 | If any voting member of a replica set uses the in-memory storage engine, you must set writeConcernMajorityJournalDefault to false. 77 | 如果副本集的任何有投票权的成员使用内存存储引擎,则必须将writeConcernMajorityJournalDefault设置为false。 78 | 79 | > NOTE 注意 80 | > 81 | > Starting in version 4.2 (and 4.0.13 and 3.6.14 ), if a replica set member uses the in-memory storage engine (voting or non-voting) but the replica set has writeConcernMajorityJournalDefault set to true, the replica set member logs a startup warning. 82 | 从版本4.2(以及4.0.13和3.6.14)开始,如果副本集成员使用内存中的存储引擎(投票或不投票),但是副本集的writeConcernMajorityJournalDefault设置为true,则副本集成员记录a 启动警告。 83 | With writeConcernMajorityJournalDefault set to false, MongoDB does not wait for w: "majority" writes to be written to the on-disk journal before acknowledging the writes. As such, majority write operations could possibly roll back in the event of a transient loss (e.g. crash and restart) of a majority of nodes in a given replica set. 84 | 将writeConcernMajorityJournalDefault设置为false时,MongoDB不会等待w:在确认写入之前,“多数”写入将写入磁盘日志。 这样,如果给定副本集中大多数节点的瞬时丢失(例如崩溃和重新启动),多数写入操作可能会回滚。 85 | 86 | Write operations that specify a write concern journaled are acknowledged immediately. When an mongod instance shuts down, either as result of the shutdown command or due to a system error, recovery of in-memory data is impossible. 87 | 立即记录指定日记记录的写关注点的写操作。 当mongod实例由于shutdown命令或由于系统错误而关闭时,无法恢复内存中的数据。 88 | 89 | ## Transactions 90 | 91 | Starting in MongoDB 4.2, transactions are supported on replica sets and sharded clusters where: 92 | 从MongoDB 4.2开始,副本集和分片群集上支持事务,其中: 93 | the primary uses the WiredTiger storage engine, and the secondary members use either the WiredTiger storage engine or the in-memory storage engines. 94 | In MongoDB 4.0, only replica sets using the WiredTiger storage engine supported transactions. 95 | 主要成员使用WiredTiger存储引擎,辅助成员使用WiredTiger存储引擎或内存中存储引擎。 96 | 在MongoDB 4.0中,仅使用WiredTiger存储引擎的副本集支持事务。 97 | > NOTE注意 98 | > 99 | > You cannot run transactions on a sharded cluster that has a shard with writeConcernMajorityJournalDefault set to false, such as a shard with a voting member that uses the in-memory storage engine. 100 | 您无法在具有将writeConcernMajorityJournalDefault设置为false的分片的分片群集上运行事务,例如,具有使用in-memory 内存存储引擎的投票成员的分片集群。 101 | 102 | ## Deployment Architectures 部署架构 103 | 104 | In addition to running as standalones, mongod instances that use in-memory storage engine can run as part of a replica set or part of a sharded cluster. 105 | 除了独立运行外,使用in-memory内存存储引擎的mongod实例还可以作为副本集的一部分或分片群集的一部分运行。 106 | 107 | ### Replica Set 复制集 108 | 109 | You can deploy mongod instances that use in-memory storage engine as part of a replica set. For example, as part of a three-member replica set, you could have: 110 | 可以部署将in-memory内存存储引擎用作副本集一部分的mongod实例。 例如,作为三副本集的一部分,您可能需要修改配置: 111 | - two mongod instances run with in-memory storage engine.两个mongod实例与内存存储引擎一起运行。 112 | - one mongod instance run with WiredTiger storage engine. Configure the WiredTiger member as a hidden member (i.e. hidden: true and priority: 0).一个使用WiredTiger存储引擎运行的mongod实例。 将WiredTiger成员配置为隐藏成员(即hidden:true和优先级:0)。 113 | 114 | With this deployment model, only the mongod instances running with the in-memory storage engine can become the primary. Clients connect only to the in-memory storage engine mongod instances. Even if both mongod instances running in-memory storage engine crash and restart, they can sync from the member running WiredTiger. The hidden mongod instance running with WiredTiger persists the data to disk, including the user data, indexes, and replication configuration information. 115 | 116 | 使用此部署模型,只有与in-memory内存存储引擎一起运行的mongod实例才能成为主要实例。 客户端仅连接到内存存储引擎mongod实例。 即使两个运行内存存储引擎的mongod实例都崩溃并重新启动,它们也可以从运行WiredTiger的成员进行同步。 与WiredTiger一起运行的隐藏mongod实例会将数据持久保存到磁盘,包括用户数据,索引和复制配置信息。 117 | 118 | > NOTE 注意 119 | > 120 | > In-memory storage engine requires that all its data (including oplog if mongod is part of replica set, etc.) fit into the specified --inMemorySizeGB command-line option or storage.inMemory.engineConfig.inMemorySizeGB setting. See Memory Use. 121 | In-memory内存存储引擎要求其所有数据(如果mongod是副本集的一部分,则包括oplog等)都应适合指定的--inMemorySizeGB命令行选项或storage.inMemory.engineConfig.inMemorySizeGB设置。 请参阅内存使用。 122 | 123 | ### Sharded Cluster 分片集群 124 | 125 | You can deploy mongod instances that use in-memory storage engine as part of a sharded cluster. For example, in a sharded cluster, you could have one shard that has consists of the following replica set: 126 | 可以将使用内存存储引擎的mongod实例部署为分片群集的一部分。 例如,在分片群集中,您可以拥有一个由以下副本集组成的分片: 127 | 128 | - two mongod instances run with in-memory storage engine 两个mongod实例与内存存储引擎一起运行 129 | - one mongod instance run with WiredTiger storage engine. Configure the WiredTiger member as a hidden member (i.e. hidden: true and priority: 0). 一个WiredTiger存储引擎运行的mongod实例。 将WiredTiger成员配置为隐藏成员(即hidden:true和优先级:0)。 130 | 131 | To this shard, add the tag inmem. For example, if this shard has the name shardC, connect to the mongos and run sh.addShardTag(). 132 | 在此分片节点上,添加标记inmem。 例如,如果此分片的名称为shardC,请连接到mongos并运行sh.addShardTag()命令,添加标签。 133 | 134 | For example, 135 | sh.addShardTag("shardC", "inmem") 136 | To the other shards, add a separate tag persisted . 137 | 例如, 138 | sh.addShardTag(“ shardC”,“ inmem”) 139 | 向其他分片添加一个单独的标签persisted。 140 | 141 | ``` 142 | sh.addShardTag("shardA", "persisted") 143 | sh.addShardTag("shardB", "persisted") 144 | ``` 145 | For each sharded collection that should reside on the inmem shard, assign to the entire chunk range the tag inmem: 146 | 对于应驻留在inmem分片上的每个分片集合,将标签inmem分配给整个块范围: 147 | ``` 148 | `sh.addTagRange("test.analytics", { shardKey: MinKey }, { shardKey: MaxKey }, "inmem")` 149 | ``` 150 | For each sharded collection that should reside across the persisted shards, assign to the entire chunk range the tag persisted: 151 | 对于应该驻留在持久化分片上的每个分片集合,将标签持久化分配给整个块范围: 152 | ``` 153 | `sh.addTagRange("salesdb.orders", { shardKey: MinKey }, { shardKey: MaxKey }, "persisted")` 154 | ``` 155 | 156 | 原文链接:[https://docs.mongodb.com/manual/core/inmemory/](https://docs.mongodb.com/manual/core/inmemory/) 157 | 158 | 译者:徐雷 -------------------------------------------------------------------------------- /15 Frequently Asked Questions 常见问题/15-02 FAQ Indexes常见问题:索引.md: -------------------------------------------------------------------------------- 1 | # FAQ: Indexes 2 | 3 | # 常见问题:索引[¶](https://docs.mongodb.com/manual/faq/indexes/#faq-indexes) 4 | 5 | On this page 6 | 7 | - [How do I create an index?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-create-an-index) 8 | - [How does an index build affect database performance?](https://docs.mongodb.com/manual/faq/indexes/#how-does-an-index-build-affect-database-performance) 9 | - [How do I see what indexes exist on a collection?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-see-what-indexes-exist-on-a-collection) 10 | - [How can I see if a query uses an index?](https://docs.mongodb.com/manual/faq/indexes/#how-can-i-see-if-a-query-uses-an-index) 11 | - [How do I determine which fields to index?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-determine-which-fields-to-index) 12 | - [How can I see the size of an index?](https://docs.mongodb.com/manual/faq/indexes/#how-can-i-see-the-size-of-an-index) 13 | - [How do write operations affect indexes?](https://docs.mongodb.com/manual/faq/indexes/#how-do-write-operations-affect-indexes) 14 | 15 | 在本页面 16 | 17 | - [如何创建索引?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-create-an-index) 18 | - [索引构建如何影响数据库性能?](https://docs.mongodb.com/manual/faq/indexes/#how-does-an-index-build-affect-database-performance) 19 | - [如何查看集合中存在哪些索引?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-see-what-indexes-exist-on-a-collection) 20 | - [如何查看查询是否使用索引?](https://docs.mongodb.com/manual/faq/indexes/#how-can-i-see-if-a-query-uses-an-index) 21 | - [如何确定要索引的字段?](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-determine-which-fields-to-index) 22 | - [如何查看索引的大小?](https://docs.mongodb.com/manual/faq/indexes/#how-can-i-see-the-size-of-an-index) 23 | - [写操作如何影响索引?](https://docs.mongodb.com/manual/faq/indexes/#how-do-write-operations-affect-indexes) 24 | 25 | This document addresses some common questions regarding MongoDB [indexes](https://docs.mongodb.com/manual/indexes/). For more information on indexes, see [Indexes](https://docs.mongodb.com/manual/indexes/). 26 | 27 | 本文档解决了有关MongoDB [索引的](https://docs.mongodb.com/manual/indexes/)一些常见问题 。有关索引的更多信息,请参见 [Indexes](https://docs.mongodb.com/manual/indexes/)。 28 | 29 | 30 | 31 | ## How do I create an index?如何创建索引?[¶](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-create-an-index) 32 | 33 | To create an index on a collection, use the [`db.collection.createIndex()`](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#db.collection.createIndex) method. Creating an index is an administrative operation. In general, applications should not call [`db.collection.createIndex()`](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#db.collection.createIndex) on a regular basis. 34 | 35 | 要在集合上创建索引,请使用 [`db.collection.createIndex()`](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#db.collection.createIndex)方法。创建索引是一种管理性操作。通常,应用程序不应定期调用 [`db.collection.createIndex()`](https://docs.mongodb.com/manual/reference/method/db.collection.createIndex/#db.collection.createIndex)。 36 | 37 | NOTE 38 | 39 | Index builds can impact performance; see [How does an index build affect database performance?](https://docs.mongodb.com/manual/faq/indexes/#faq-index-performance). Administrators should consider the performance implications before building indexes. 40 | 41 | 注意 42 | 43 | 索引构建会影响性能;请参见 [索引构建如何影响数据库性能?](https://docs.mongodb.com/manual/faq/indexes/#faq-index-performance)。管理员应在建立索引之前考虑性能影响。 44 | 45 | 46 | 47 | ## How does an index build affect database performance? 48 | 49 | ## 索引构建如何影响数据库性能?[¶](https://docs.mongodb.com/manual/faq/indexes/#how-does-an-index-build-affect-database-performance) 50 | 51 | MongoDB index builds against a populated collection require an exclusive read-write lock against the collection. Operations that require a read or write lock on the collection must wait until the [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) releases the lock. 52 | 53 | 针对已填充集合的MongoDB索引构建,需要针对该集合进行排他性读写锁定。在[`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod)释放锁定之前需要对集合进行读取或写入锁定的操作必须等待。 54 | 55 | *Changed in version 4.2.**在版本4.2中进行了更改。* 56 | 57 | - For [feature compatibility version (fcv)](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#view-fcv) `"4.2"`, MongoDB uses an optimized build process that only holds the exclusive lock at the beginning and end of the index build. The rest of the build process yields to interleaving read and write operations. 58 | - For [feature compatibility version (fcv)](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#view-fcv) `"4.0"`, the default foreground index build process holds the exclusive lock for the entire index build. `background` index builds do *not* take an exclusive lock during the build process. 59 | 60 | - 对于[功能兼容版本(fcv)](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#view-fcv) `"4.2"`,MongoDB使用优化的构建过程,该过程仅在索引构建的开始和结束时都保留排他锁。其余的构建过程将产生交叉的读写操作。 61 | - 对于[功能兼容版本(fcv)](https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/#view-fcv) `"4.0"`,默认的前台索引构建过程将保留整个索引构建的互斥锁。`background`索引在构建过程中*不会*获得排他锁。 62 | 63 | For more information on the index build process, see [Index Builds on Populated Collections](https://docs.mongodb.com/manual/core/index-creation/#index-operations). 64 | 65 | 有关索引构建过程的更多信息,请参见[填充集合](https://docs.mongodb.com/manual/core/index-creation/#index-operations)上的索引构建 。 66 | 67 | Index builds on replica sets have specific performance considerations and risks. See [Index Builds in Replicated Environments](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build) for more information. To minimize the impact of building an index on replica sets, including shard replica sets, use a rolling index build procedure as described in [Build Indexes on Replica Sets](https://docs.mongodb.com/manual/tutorial/build-indexes-on-replica-sets/). 68 | 69 | 基于副本集的索引具有特定的性能考虑因素和风险。有关更多信息,请参见[复制环境中的索引构建](https://docs.mongodb.com/manual/core/index-creation/#index-operations-replicated-build)。为了最大程度地减少对副本集(包括分片副本集)建立索引的影响,请使用在[副本集上建立索引中](https://docs.mongodb.com/manual/tutorial/build-indexes-on-replica-sets/)所述的滚动索引[生成](https://docs.mongodb.com/manual/tutorial/build-indexes-on-replica-sets/)过程。 70 | 71 | To return information on currently running index creation operations, see [Active Indexing Operations](https://docs.mongodb.com/manual/reference/method/db.currentOp/#currentop-index-creation). To kill a running index creation operation on a [primary](https://docs.mongodb.com/manual/reference/glossary/#term-primary) or standalone [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod), use [`db.killOp()`](https://docs.mongodb.com/manual/reference/method/db.killOp/#db.killOp). The partially built index will be deleted. 72 | 73 | 要返回当前正在运行的索引创建操作的相关信息,请参阅[Active Indexing Operations](https://docs.mongodb.com/manual/reference/method/db.currentOp/#currentop-index-creation)。要在[主数据库](https://docs.mongodb.com/manual/reference/glossary/#term-primary)或独立数据库上终止正在运行的索引创建操作[`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod),请使用 [`db.killOp()`](https://docs.mongodb.com/manual/reference/method/db.killOp/#db.killOp)。部分构建的索引将被删除。 74 | 75 | You cannot terminate a *replicated* index build on secondary members of a replica set. You must first [`drop`](https://docs.mongodb.com/manual/reference/method/db.collection.dropIndex/#db.collection.dropIndex) the index on the primary. The secondaries will replicate the drop operation and drop the indexes *after* the index build completes. All further replication blocks behind the index build and drop. 76 | 77 | 您不能在副本集的辅助成员上终止*复制*索引构建。您必须首先在主数据库上删除索引。二级服务器将复制删除操作,并在索引构建完成*后*删除索引。索引建立和删除之后的所有其他复制将会终止。 78 | 79 | 80 | 81 | ## How do I see what indexes exist on a collection?如何查看集合中存在哪些索引?[¶](https://docs.mongodb.com/manual/faq/indexes/#how-do-i-see-what-indexes-exist-on-a-collection) 82 | 83 | To list a collection’s indexes, use the [`db.collection.getIndexes()`](https://docs.mongodb.com/manual/reference/method/db.collection.getIndexes/#db.collection.getIndexes) method.要列出集合的索引,请使用 [`db.collection.getIndexes()`](https://docs.mongodb.com/manual/reference/method/db.collection.getIndexes/#db.collection.getIndexes)方法。 84 | 85 | 86 | 87 | ## How can I see if a query uses an index?如何查看查询是否使用索引? 88 | 89 | To inspect how MongoDB processes a query, use the [`explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain) method.要检查MongoDB如何处理查询,请使用 [`explain()`](https://docs.mongodb.com/manual/reference/method/cursor.explain/#cursor.explain)方法。 90 | 91 | ## How do I determine which fields to index?如何确定要索引的字段? 92 | 93 | A number of factors determine which fields to index, including [selectivity](https://docs.mongodb.com/manual/tutorial/create-queries-that-ensure-selectivity/#index-selectivity), the support for multiple [query shapes](https://docs.mongodb.com/manual/reference/glossary/#term-query-shape), and [size of the index](https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/). For more information, see [Operational Considerations for Indexes](https://docs.mongodb.com/manual/core/data-model-operations/#data-model-indexes) and [Indexing Strategies](https://docs.mongodb.com/manual/applications/indexes/). 94 | 95 | 许多因素决定要索引的字段,包括 [选择性](https://docs.mongodb.com/manual/tutorial/create-queries-that-ensure-selectivity/#index-selectivity),对多种[查询](https://docs.mongodb.com/manual/reference/glossary/#term-query-shape)的支持 以及[索引的大小](https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/)。更多信息,请参见 [索引操作注意事项](https://docs.mongodb.com/manual/core/data-model-operations/#data-model-indexes)和 [索引策略](https://docs.mongodb.com/manual/applications/indexes/)。 96 | 97 | 98 | 99 | ## How can I see the size of an index?如何查看索引的大小?[¶](https://docs.mongodb.com/manual/faq/indexes/#how-can-i-see-the-size-of-an-index) 100 | 101 | The [`db.collection.stats()`](https://docs.mongodb.com/manual/reference/method/db.collection.stats/#db.collection.stats) includes an [`indexSizes`](https://docs.mongodb.com/manual/reference/command/collStats/#collStats.indexSizes) document which provides size information for each index on the collection. 102 | 103 | [`db.collection.stats()`](https://docs.mongodb.com/manual/reference/method/db.collection.stats/#db.collection.stats)包括一个为集合中的每个索引提供了大小信息的[`indexSizes`](https://docs.mongodb.com/manual/reference/command/collStats/#collStats.indexSizes)文档。 104 | 105 | Depending on its size, an index may not fit into RAM. An index fits into RAM when your server has enough RAM available for both the index and the rest of the [working set](https://docs.mongodb.com/manual/reference/glossary/#term-working-set). When an index is too large to fit into RAM, MongoDB must read the index from disk, which is a much slower operation than reading from RAM. 106 | 107 | 根据其大小,一个索引可能无法放入内存。当您的服务器具有足够的RAM用于索引和其余[工作集](https://docs.mongodb.com/manual/reference/glossary/#term-working-set)时,索引将加载进内存。当索引太大而无法放入RAM时,MongoDB必须从磁盘读取索引,这比从RAM读取要慢得多。 108 | 109 | In certain cases, an index does not need to fit *entirely* into RAM. For details, see [Indexes that Hold Only Recent Values in RAM](https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/#indexing-right-handed). 110 | 111 | 在某些情况下,索引不必*完全*适合RAM。有关详细信息,请参阅[仅在RAM中保存最近使用值的索引](https://docs.mongodb.com/manual/tutorial/ensure-indexes-fit-ram/#indexing-right-handed)。 112 | 113 | 114 | 115 | ## How do write operations affect indexes?写操作如何影响索引? 116 | 117 | Write operations may require updates to indexes: 118 | 119 | - If a write operation modifies an indexed field, MongoDB updates all indexes that have the modified field as a key. 120 | 121 | Therefore, if your application is write-heavy, indexes might affect performance. 122 | 123 | 写操作可能需要更新索引: 124 | 125 | - 如果写入操作修改了索引字段,则MongoDB将更新所有键中包含该字段的索引。 126 | 127 | 因此,如果您的应用程序是大量写入操作,则索引可能会影响性能。 128 | 129 | 130 | 131 | 原文链接:https://docs.mongodb.com/manual/faq/indexes/ 132 | 133 | 译者:钟秋 134 | 135 | update:小芒果 -------------------------------------------------------------------------------- /15 Frequently Asked Questions 常见问题/15-05 FAQ Replication and Replica Sets常见问题:复制和副本集.md: -------------------------------------------------------------------------------- 1 | # FAQ: Replication and Replica Sets 2 | 3 | # 常见问题:复制和副本集[¶](https://docs.mongodb.com/manual/faq/replica-sets/#faq-replication-and-replica-sets) 4 | 5 | On this page 6 | 7 | - [What kind of replication does MongoDB support?](https://docs.mongodb.com/manual/faq/replica-sets/#what-kind-of-replication-does-mongodb-support) 8 | - [Does replication work over the Internet and WAN connections?](https://docs.mongodb.com/manual/faq/replica-sets/#does-replication-work-over-the-internet-and-wan-connections) 9 | - [Can MongoDB replicate over a “noisy” connection?](https://docs.mongodb.com/manual/faq/replica-sets/#can-mongodb-replicate-over-a-noisy-connection) 10 | - [Why use journaling if replication already provides data redundancy?](https://docs.mongodb.com/manual/faq/replica-sets/#why-use-journaling-if-replication-already-provides-data-redundancy) 11 | - [What information do arbiters exchange with the rest of the replica set?](https://docs.mongodb.com/manual/faq/replica-sets/#what-information-do-arbiters-exchange-with-the-rest-of-the-replica-set) 12 | - [Is it normal for replica set members to use different amounts of disk space?](https://docs.mongodb.com/manual/faq/replica-sets/#is-it-normal-for-replica-set-members-to-use-different-amounts-of-disk-space) 13 | - [Can I rename a replica set?](https://docs.mongodb.com/manual/faq/replica-sets/#can-i-rename-a-replica-set) 14 | 15 | 在本页面 16 | 17 | - [MongoDB支持哪种复制?](https://docs.mongodb.com/manual/faq/replica-sets/#what-kind-of-replication-does-mongodb-support) 18 | - [复制是否可以通过Internet和WAN连接进行?](https://docs.mongodb.com/manual/faq/replica-sets/#does-replication-work-over-the-internet-and-wan-connections) 19 | - [MongoDB可以通过“noisy”连接进行复制吗?](https://docs.mongodb.com/manual/faq/replica-sets/#can-mongodb-replicate-over-a-noisy-connection) 20 | - [如果复制已经提供了数据冗余,为什么还要使用journaling(预写日志,WAL)功能?](https://docs.mongodb.com/manual/faq/replica-sets/#why-use-journaling-if-replication-already-provides-data-redundancy) 21 | - [仲裁节点与副本集的其它节点交换哪些信息?](https://docs.mongodb.com/manual/faq/replica-sets/#what-information-do-arbiters-exchange-with-the-rest-of-the-replica-set) 22 | - [副本集成员使用不同大小的磁盘空间是否正常?](https://docs.mongodb.com/manual/faq/replica-sets/#is-it-normal-for-replica-set-members-to-use-different-amounts-of-disk-space) 23 | - [我可以重命名副本集吗?](https://docs.mongodb.com/manual/faq/replica-sets/#can-i-rename-a-replica-set) 24 | 25 | This document answers common questions about replication in MongoDB. See also the [Replication](https://docs.mongodb.com/manual/replication/) section in the manual, which provides an [overview of replication](https://docs.mongodb.com/manual/replication/), including details on: 26 | 27 | 本文档回答了有关MongoDB中复制的常见问题。另请参见手册中的“ [复制”](https://docs.mongodb.com/manual/replication/)部分,其中[概述了复制](https://docs.mongodb.com/manual/replication/),包括有关以下方面的详细信息: 28 | 29 | - [Replica Set Members](https://docs.mongodb.com/manual/core/replica-set-members/) 30 | 31 | - [Replica Set Deployment Architectures](https://docs.mongodb.com/manual/core/replica-set-architectures/) 32 | 33 | - [Replica Set Elections](https://docs.mongodb.com/manual/core/replica-set-elections/) 34 | 35 | - [副本集成员](https://docs.mongodb.com/manual/core/replica-set-members/) 36 | 37 | - [副本集部署体系结构](https://docs.mongodb.com/manual/core/replica-set-architectures/) 38 | 39 | - [副本集选举](https://docs.mongodb.com/manual/core/replica-set-elections/) 40 | 41 | 42 | 43 | ## What kind of replication does MongoDB support?MongoDB支持哪种复制? 44 | 45 | MongoDB supports [replica sets](https://docs.mongodb.com/manual/replication/), which can have up to [50 nodes](https://docs.mongodb.com/manual/release-notes/3.0/#replica-sets-max-members). 46 | 47 | MongoDB支持[副本集](https://docs.mongodb.com/manual/replication/),[副本集](https://docs.mongodb.com/manual/replication/)最多可包含[50个节点](https://docs.mongodb.com/manual/release-notes/3.0/#replica-sets-max-members)。 48 | 49 | 50 | 51 | ## Does replication work over the Internet and WAN connections?复制是否可以通过Internet和WAN连接进行? 52 | 53 | Yes. 54 | 55 | For example, a deployment may maintain a [primary](https://docs.mongodb.com/manual/reference/glossary/#term-primary) and [secondary](https://docs.mongodb.com/manual/reference/glossary/#term-secondary) in an East-coast data center along with a [secondary](https://docs.mongodb.com/manual/reference/glossary/#term-secondary) member for disaster recovery in a West-coast data center. 56 | 57 | 可以。 58 | 59 | 例如,在东海岸数据中心可以部署一个[主节点](https://docs.mongodb.com/manual/reference/glossary/#term-primary)和一个[副节点](https://docs.mongodb.com/manual/reference/glossary/#term-secondary) ,以及在西海岸数据中心部署一个作为灾难恢复的[从节点](https://docs.mongodb.com/manual/reference/glossary/#term-secondary)成员。 60 | 61 | SEE ALSO 62 | 63 | [Deploy a Geographically Redundant Replica Set](https://docs.mongodb.com/manual/tutorial/deploy-geographically-distributed-replica-set/) 64 | 65 | 参见 66 | 67 | [部署异地冗余的副本集](https://docs.mongodb.com/manual/tutorial/deploy-geographically-distributed-replica-set/) 68 | 69 | 70 | 71 | ## Can MongoDB replicate over a “noisy” connection?MongoDB可以通过“noisy”的连接进行复制吗? 72 | 73 | Yes, but not without connection failures and the obvious latency. 74 | 75 | 是的,但连接失败和非常明显的延迟的情况下不行。 76 | 77 | Members of the set will attempt to reconnect to the other members of the set in response to networking flaps. This does not require administrator intervention. However, if the network connections among the nodes in the replica set are very slow, it might not be possible for the members of the node to keep up with the replication. 78 | 79 | 集合中的成员将尝试重新连接到集合中的其他成员,以响应网络波动。这不需要管理员干预。但是,如果副本集中节点之间的网络连接非常慢,则节点成员可能无法跟上复制。 80 | 81 | SEE ALSO 82 | 83 | [Replica Set Elections](https://docs.mongodb.com/manual/core/replica-set-elections/) 84 | 85 | 参见 86 | 87 | [副本集选举](https://docs.mongodb.com/manual/core/replica-set-elections/) 88 | 89 | 90 | 91 | ## Why use journaling if replication already provides data redundancy?如果复制已经提供了数据冗余,为什么还要使用journaling(预写日志,WAL)功能? 92 | 93 | [Journaling](https://docs.mongodb.com/manual/reference/glossary/#term-journal) facilitates faster crash recovery.[Journaling](https://docs.mongodb.com/manual/reference/glossary/#term-journal)功能有助于加快崩溃恢复速度。 94 | 95 | Journaling is particularly useful for protection against power failures, especially if your replica set resides in a single data center or power circuit.Journaling功能对于防止电源故障特别有用,尤其是当副本集位于单个数据中心或电源电路中时。 96 | 97 | When a [replica set](https://docs.mongodb.com/manual/reference/glossary/#term-replica-set) runs with journaling, you can safely restart [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod) instances without additional intervention. 98 | 99 | 当[副本集](https://docs.mongodb.com/manual/reference/glossary/#term-replica-set)与Journaling一起运行时,您可以安全地重新启动 [`mongod`](https://docs.mongodb.com/manual/reference/program/mongod/#bin.mongod)实例,而无需其他干预。 100 | 101 | NOTE 102 | 103 | Journaling requires some resource overhead for write operations. Journaling has no effect on read performance, however. 104 | 105 | Journaling is enabled by default on all 64-bit builds of MongoDB v2.0 and greater. 106 | 107 | 注意 108 | 109 | Journaling记录需要一些资源开销来进行写操作。但是,Journaling对读取性能没有影响。 110 | 111 | 默认情况下,在MongoDB v2.0及更高版本的所有64位版本上都启用Journaling功能。 112 | 113 | 114 | 115 | ## What information do arbiters exchange with the rest of the replica set? 116 | 117 | ## 仲裁节点与副本集的其余节点交换哪些信息? 118 | 119 | Arbiters never receive the contents of a collection but do exchange the following data with the rest of the replica set: 120 | 121 | - Credentials used to authenticate the arbiter with the replica set. These exchanges are encrypted. 122 | - Replica set configuration data and voting data. This information is not encrypted. Only credential exchanges are encrypted. 123 | 124 | 仲裁节点永远不会复制集合的数据内容,但会与副本集的其余节点交换以下数据: 125 | 126 | - 用于副本集认证仲裁节点的凭据。这些交换数据是加密的。 127 | - 副本集配置数据和投票数据。此信息未加密。仅加密交换凭证。 128 | 129 | If your MongoDB deployment uses TLS/SSL, then all communications between arbiters and the other members of the replica set are secure. 130 | 131 | 如果您的MongoDB部署使用TLS / SSL,则仲裁节点与副本集其他成员之间的所有通信都是安全的。 132 | 133 | See the documentation for [Configure mongod and mongos for TLS/SSL](https://docs.mongodb.com/manual/tutorial/configure-ssl/) for more information. As with all MongoDB components, run arbiters on secure networks. 134 | 135 | 有关更多信息,请参阅有关[为TLS / SSL配置mongod和mongos](https://docs.mongodb.com/manual/tutorial/configure-ssl/)的文档。与所有MongoDB组件一样,应该在安全网络上运行仲裁节点。 136 | 137 | SEE 138 | 139 | The overview of [Arbiter Members of Replica Sets](https://docs.mongodb.com/manual/core/replica-set-members/#replica-set-arbiters). 140 | 141 | 参见 142 | 143 | [副本集仲裁成员](https://docs.mongodb.com/manual/core/replica-set-members/#replica-set-arbiters)概述 。 144 | 145 | 146 | 147 | ## Is it normal for replica set members to use different amounts of disk space? 148 | 149 | ## 副本集成员使用不同大小的磁盘空间是否正常? 150 | 151 | Yes. 152 | 153 | Factors including: different oplog sizes, different levels of storage fragmentation, and MongoDB’s data file pre-allocation can lead to some variation in storage utilization between nodes. Storage use disparities will be most pronounced when you add members at different times. 154 | 155 | 正常。 156 | 157 | 因素包括:不同的oplog大小,不同程度的存储碎片以及MongoDB的数据文件预分配,都可能导致节点之间的存储利用率发生一些变化。当您在不同时间添加成员时,存储使用差异将最为明显。(译者注:可以理解为先后添加,因此上述存储碎片程度等差异就会比较明显,从而导致影响磁盘占用不同)。 158 | 159 | 160 | 161 | ## Can I rename a replica set?我可以重命名副本集吗? 162 | 163 | No. 164 | 165 | You can use the backup and restore procedure described in the [Restore a Replica Set from MongoDB Backups](https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/) tutorial to create a new replica set with the desired name. Downtime may be necessary in order to ensure parity between the original replica set and the new one. 166 | 167 | 不可以。 168 | 169 | 您可以使用“ [从MongoDB备份还原副本集”](https://docs.mongodb.com/manual/tutorial/restore-replica-set-from-backup/)教程中描述的备份和还原过程来创建具有所需名称的新副本集。为了确保原始副本集和新副本集之间的奇偶校验,可能需要停机。 170 | 171 | 172 | 173 | 原文链接:https://docs.mongodb.com/manual/faq/replica-sets/ 174 | 175 | 译者:钟秋 176 | 177 | update:小芒果 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MongoDB-4.2-Manual 2 | 3 | 本文档由MongoDB中文社区(mongoing.com)[翻译小组](https://mongoing.com/translators) 进行翻译,翻译原文来自MongoDB官网用户手册:https://docs.mongodb.com/manual/ 4 | 5 | MongoDB中文社区是MongoDB官方支持的MongoDB爱好者交流平台。中文社区由博客、线下活动、技术问答、官方文档翻译等版块组成,迄今为止已经举办了数十场线下活动和线上直播,发表了数百篇技术文章及文档,在社区里支持了数万计的 MongoDB 用户。 6 | 7 | 欢迎申请加入翻译小组,或者直接对我们成员朋友的翻译提交修改建议。 8 | 9 | 申请加入请联系MongoDB中文社区助理 小芒果,微信:mongoingcom 10 | 11 |
12 |
13 | 14 | 更多信息请访问: 15 | [MongoDB中文社区:mongoing.com](https://mongoing.com/) 16 | 17 | 相关公众号: 18 | 19 | Mongoing中文社区—— MongoDB实践一手干货,社区用户大会最新资讯; 20 | 21 | MongoDB数据库—— MongoDB官方微信; 22 | 23 | MongoDB中文用户组 —— MongoDB用户手册最新翻译发布。 24 | (本资料库内容的更新将会以全中文格式发布到MongoDB中文用户组上哦) 25 | 26 |
27 |
28 | 29 | 30 | Contribute 31 | ---------- 32 | 33 | The MongoDB Documentation Project is governed by the terms of the 34 | [MongoDB Contributor Agreement](https://www.mongodb.com/legal/contributor-agreement) 35 | 36 | To contribute to the documentation, 37 | 38 | - If you have not done so already, please sign the [MongoDB Contributor Agreement ](https://www.mongodb.com/legal/contributor-agreement) 39 | 40 | - Fork this repository on GitHub and issue a pull request. 41 | 42 | Report Issues 43 | ------------- 44 | 45 | To file issues or requests regarding the documentation, go to the 46 | [Documentation Jira Project](https://jira.mongodb.org/browse/DOCS). 47 | 48 | License 49 | ------- 50 | 51 | All documentation is available under the terms of a [Creative Commons 52 | License](https://creativecommons.org/licenses/by-nc-sa/3.0/) 53 | If you have any questions, please contact `docs@mongodb.com 54 | `_. 55 | 56 | -- The MongoDB Documentation Team 57 | -------------------------------------------------------------------------------- /docs/readme.md: -------------------------------------------------------------------------------- 1 | # MongoDB-4.2-Manual 2 | 3 | 本文档由MongoDB中文社区(mongoing.com)[翻译小组](https://mongoing.com/translators) 进行翻译,翻译原文来自MongoDB官网用户手册:https://docs.mongodb.com/manual/ 4 | 5 | MongoDB中文社区是MongoDB官方支持的MongoDB爱好者交流平台。中文社区由博客、线下活动、技术问答、官方文档翻译等版块组成,迄今为止已经举办了数十场线下活动和线上直播,发表了数百篇技术文章及文档,在社区里支持了数万计的 MongoDB 用户。 6 | 7 | 欢迎申请加入翻译小组,或者直接对我们成员朋友的翻译提交修改建议。 8 | 9 | 申请加入请联系MongoDB中文社区助理 小芒果,微信:mongoingcom 10 | 11 |
12 |
13 | 14 | 更多信息请访问: 15 | [MongoDB中文社区:mongoing.com](https://mongoing.com/) 16 | 17 | 相关公众号: 18 | 19 | Mongoing中文社区—— MongoDB实践一手干货,社区用户大会最新资讯; 20 | 21 | MongoDB数据库—— MongoDB官方微信; 22 | 23 | MongoDB中文用户组 —— MongoDB用户手册最新翻译发布。 24 | (本资料库内容的更新将会以全中文格式发布到MongoDB中文用户组上哦) 25 | 26 |
27 |
28 | 29 | 30 | Contribute 31 | ---------- 32 | 33 | The MongoDB Documentation Project is governed by the terms of the 34 | [MongoDB Contributor Agreement](https://www.mongodb.com/legal/contributor-agreement) 35 | 36 | To contribute to the documentation, 37 | 38 | - If you have not done so already, please sign the [MongoDB Contributor Agreement ](https://www.mongodb.com/legal/contributor-agreement) 39 | 40 | - Fork this repository on GitHub and issue a pull request. 41 | 42 | Report Issues 43 | ------------- 44 | 45 | To file issues or requests regarding the documentation, go to the 46 | [Documentation Jira Project](https://jira.mongodb.org/browse/DOCS). 47 | 48 | License 49 | ------- 50 | 51 | All documentation is available under the terms of a [Creative Commons 52 | License](https://creativecommons.org/licenses/by-nc-sa/3.0/) 53 | If you have any questions, please contact `docs@mongodb.com 54 | `_. 55 | 56 | -- The MongoDB Documentation Team 57 | --------------------------------------------------------------------------------