发布于 2015-09-14 15:12:02 | 119 次阅读 | 评论: 0 | 来源: 网络整理

The aggregation framework allows MongoDB to provide native aggregation capabilities that corresponds to many common data aggregation operations in SQL. If you’re new to MongoDB you might want to consider the 常问问题 section for a selection of common questions.

The following table provides an overview of common SQL aggregation terms, functions, and concepts and the corresponding MongoDB aggregation operators:

实例

The following table presents a quick reference of SQL aggregation statements and the corresponding MongoDB statements. The examples in the table assume the following conditions:

  • The SQL examples assume two tables, orders and order_lineitem that join by the order_lineitem.order_id and the orders.id columns.

  • The MongoDB examples assume one collection orders that contain documents of the following prototype:

    {
      cust_id: "abc123",
      ord_date: ISODate("2012-11-02T17:04:11.102Z"),
      status: 'A',
      price: 50,
      items: [ { sku: "xxx", qty: 25, price: 1 },
               { sku: "yyy", qty: 25, price: 1 } ]
    }
    
  • The MongoDB statements prefix the names of the fields from the documents in the collection orders with a $ character when they appear as operands to the aggregation operations.

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

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