aggregation 命令 除了已经介绍过的 aggregate mapReduce
还有 count 、 distinct、group;在大多数情况下这三个已经被聚合框架取代了,
操作 | 意义 | 实例 | 备注 |
---|---|---|---|
count | 返回文档数量 | db.c.count({}) runCommand({ count: collection or view, query: document, limit: integer, skip: integer, hint: hint, readConcern: document }) | 条件查询不如 find 快 |
distinct | 返回指定键的不同值 | db.runCommand ( { distinct: “myCollection”, key: “myKey” } ) | 返回格式 { ”values” : [ “1”, “a”, “2b” ], “ok” : 1 } |
group | 分组 | db.c.group() | Mongodb 3.4后建议使用db.collection.aggregate() 或者 db.collection.mapReduce() |