发布于 2015-09-14 14:44:24 | 250 次阅读 | 评论: 0 | 来源: 网络整理

aggregate

2.1.0 新版功能.

aggregate implements the aggregation framework. Consider the following prototype form:

{ aggregate: "[collection]", pipeline: [pipeline] }

Where [collection] specifies the name of the collection that contains the data that you wish to aggregate. The pipeline argument holds an array that contains the specification for the aggregation operation. Consider the following example from the aggregation documentation.

db.runCommand(
{ aggregate : "article", pipeline : [
  { $project : {
     author : 1,
     tags : 1,
  } },
  { $unwind : "$tags" },
  { $group : {
     _id : "$tags",
     authors : { $addToSet : "$author" }
  } }
 ] }
);

More typically this operation would use the aggregate() helper in the mongo shell, and would resemble the following:

db.article.aggregate(
  { $project : {
     author : 1,
     tags : 1,
  } },
  { $unwind : "$tags" },
  { $group : {
     _id : "$tags",
     authors : { $addToSet : "$author" }
  } }
);

For more aggregation documentation, please see:

最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务