{
aggregate: "<collection>" || 1, pipeline: [ <stage>, <...>],
explain: <boolean>, allowDiskUse: <boolean>,
cursor: <doc>,
maxTimeMS: <int>,
bypassDocumentValidation: <boolean>,
readConcern: <doc>,
collation: <doc>,
hint: <string or doc>,
comment: <string>,
writeConcern: <doc>
}
| 字段 | 类型 | 说明 |
| aggregate | string | 它包含聚合管道的名称 |
| pipeline | array | 将文档列表转换为聚合管道一部分的数组。 |
| explain | boolean | explain字段是可选的,用于返回有关管道处理的信息。 |
| allowDiskUse | boolean | 它使命令能够写入临时文件。 |
| cursor | document | 它处理包含用于创建光标对象的控制选项的文档。 |
| maxTimeMS | non-negative integer | 它定义了对游标进行处理的时间限制。 |
| Bypass Document Validation |
boolean | 仅在您指定out或merge聚合阶段时才适用。 |
| readConcern | document | 它指定读取关注。可能的阅读关注级别为-本地,可用,多数和可线性化。 |
| collation | document | 我们可以使用排序规则为字符串比较指定特定于语言的规则。例如-大小写和重音符号规则。
collation:
{ locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>}
|
| hint | string or document | 它通过索引名称或索引规范文档声明索引。 |
| comment | string | 我们可以声明一个任意字符串,以帮助通过数据库探查器,currentOp和日志来跟踪操作。 |
| writeConcern | document | 设置为在$out或$merge管道阶段使用默认写关注。 |
{
_id: ObjectId("52769ea0f3dc6ead47c9a1b2"),
author: "Ankit",
title: "lidihuo",
tags: [ "Java Tutorial", "DBMS Tutorial", "mongodb"]
}
db.runCommand( { aggregate: "articles", pipeline: [ { $project: { tags: 1 } }, { $unwind: "$tags" }, { $group: { _id: "$tags", count: { $sum : 1 } } } ], cursor: { } } )
{
count: <collection or view>,
query: <document>,
limit: <integer>,
skip: <integer>,
hint: <hint>,
readConcern: <document>,
collation: <document>
}
| 字段 | 类型 | 说明 |
| count | string | 这是要计数的集合或视图的名称。 |
| query | document | 它是可选的,用于选择要在集合或视图中计数的文档。 |
| limit | integer | 它是可选的,用于限制要返回的匹配文档的最大数量。 |
| skip | integer | 它是可选的,用于匹配文档以在返回结果之前跳过。 |
| hint | string | 它用于将索引名称定义为字符串或索引规范文档。 |
| readConcern document | 它指定读取关注。 | |
| collation | document | 它允许我们定义特定于语言的规则以进行字符串比较。 语法: collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
|
db.runCommand( { count: 'orders' } )
distinct: "<collection>", key: "<field>", query: <query>, readConcern: <read concern document>, collation: <collation document> }
| 字段 | 类型 | 说明 |
| distinct | string | 它是查询不同值的集合的名称 |
| key | string | 这是命令为其返回唯一值的字段。 |
| query | document | 它指定将从中检索不同值的文档。 |
| readConcern document | 它指定读取关注。 readConcern: {级别:
|
|
| collation | document | 它允许我们定义特定于语言的规则以进行字符串比较。 语法:
|
db.runCommand ( { distinct: "library", key: "books" } )
db.runCommand(
{
mapReduce: <collection>,
map: <function>,
reduce: <function>,
finalize: <function>,
out: <output>,
query: <document>,
sort: <document>,
limit: <number>,
scope: <document>,
jsMode: <boolean>,
verbose: <boolean>,
bypassDocumentValidation: <boolean>,
collation: <document>,
writeConcern: <document>
}
)
| 字段 | 类型 | 说明 |
| MapReduce | 收藏 | 这是我们要在其上执行map-reduce操作的集合的名称。 |
| map | 功能 | 这是一个JavaScript函数,用于关联或映射键值对。 |
| reduce | 功能 | 这是一个JavaScript函数,可将与特定键相关联的所有值简化为一个对象。 |
| out | string | 它指定存储输出的位置。 |
| query | document | 它指定用于确定输入到地图功能的文档的选择标准。 |
| sort | document | 它对输入文档进行排序。 |
| limit | 号码 | 它指定要输入到map函数的最大文档数。 |
| finalize | 功能 | 它遵循reduce方法来修改输出。 |
| scope | document | 这是一个选项,用于声明可在地图上访问的全局变量。 |
| jsMode | 布尔值 | jsMode指定是否将中间数据转换为BSON格式。 |
| verbose | 布尔值 | 它指定是否在结果中包括计时信息。 |
| bypass Document Validation |
布尔值 | 它使map-reduce在操作过程中绕过文档验证。 |
| collation | document | 它允许我们为字符串比较指定特定于语言的规则。
collation: {
locale: <string>,
caseLevel: <boolean>,
caseFirst: <string>,
strength: <int>,
numericOrdering: <boolean>,
alternate: <string>,
maxVariable: <string>,
backwards: <boolean>
}
|
| writeConcern | document | 这是一个文档,表达了在输出到集合时要使用的写关注点。 |
var mapFunction = function() { ... }; var reduceFunction = function(key, values) { ... }; db.runCommand({ mapReduce: <input-collection>, map: mapFunction, reduce: reduceFunction, out: { merge: <output-collection> }, query: <query> } )