Mongodb 聚合命令

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()

count文档
distinct文档
group 文档

猜你喜欢

转载自blog.csdn.net/wngzhem/article/details/80179364