connectholland/mongo-aggregations

此软件包已被废弃,不再维护。未建议替代软件包。

库,允许轻松访问mongo聚合框架

1.3.1 2016-02-08 07:51 UTC

This package is auto-updated.

Last update: 2023-05-29 00:58:37 UTC


README

Build Status StyleCI Latest Stable Version Total Downloads Latest Unstable Version License SensioLabsInsight

MongoAggregations

库,允许轻松访问mongo聚合框架

构建器

此库使用构建器构建聚合管道。您可以添加阶段(AggregationInterface的实例)、阶段的集合(AggregationBags)或其他构建器来构建您的管道。一个特殊的构建器是UnwindBuilder。此构建器将创建一个管道,可以展开字符串和数组以及包含这两种类型的数据库(后者应避免)。基本上,构建器将任何mongo字段转换为数组,然后展开该数组。

UnwindBuilder的示例用法在其测试中:https://github.com/ConnectHolland/MongoAggregations/blob/master/tests/Builder/UnwindBuilderTest.php

支持的阶段

此库目前支持聚合框架中的以下阶段

运算符 描述
匹配 $match https://docs.mongodb.org/manual/reference/operator/aggregation/match/#pipe._S_match
投影 $project https://docs.mongodb.org/manual/reference/operator/aggregation/project/#pipe._S_project
展开 $unwind https://docs.mongodb.org/manual/reference/operator/aggregation/unwind/#pipe._S_unwind
分组 $group https://docs.mongodb.org/manual/reference/operator/aggregation/group/#pipe._S_group
排序 $sort https://docs.mongodb.org/manual/reference/operator/aggregation/sort/
范围投影 一种范围投影阶段,一种特殊的$project,可以将范围(例如:1到10)映射到字符串(例如:到'low')。

支持的操作

在阶段内可以使用操作,目前支持以下操作

运算符 描述
求和 $sum https://docs.mongodb.org/manual/reference/operator/aggregation/sum/#grp._S_sum
条件 $cond https://docs.mongodb.org/manual/reference/operator/aggregation/cond/#exp._S_cond
推送 $push https://docs.mongodb.org/manual/reference/operator/aggregation/push/#grp._S_push
周操作 $week https://docs.mongodb.org/manual/reference/operator/aggregation/week/
字段操作 在投影中重命名一个字段(例如:{$project: {my_field: {'$some.field.hidden.in.complex.nesting'}}}
数组操作 在投影中使用mongo数组添加一个表达式(例如:$operation = new ArrayOperation(['$year' => '$somedate'])

嵌入式集合

该库添加了一个名为EmbeddedCollection的类,可用于创建一个(临时)集合,该集合包含另一个集合引用的文档。

不支持库的阶段或操作仍然可以通过构建数组来使用。然而,创建一个类及其抽象层更可取。