Skip to content

完善 aggregate 包 | enhancement aggregate package #29

@chenmingyong0423

Description

@chenmingyong0423

使用场景 | Use Case Scenario

Although the current aggregate package already supports building various common aggregation pipeline stages (Pipeline Stage) and expressions (Pipeline Expressions), further enhancements are needed to fully support all MongoDB aggregation pipeline stages and operators.


尽管当前的 aggregate 包已经支持构建多种常见的聚合管道阶段(Pipeline Stage)和表达式(Pipeline Expressions),但为了全面支持所有 MongoDB 聚合管道阶段和操作符,仍需对此包进行进一步的完善。

可行方案 | Feasible Solutions

Considering that aggregation operations are divided into pipeline stages and expressions, go-mongox provides two builders: aggregation.StageBuilder and aggregation.Builder:

  • For pipeline stages, it is necessary to refine the methods of the aggregation.StageBuilder constructor, adding the missing pipeline stage construction methods. Further information can be referenced at Aggregation Pipeline.

  • For pipeline expressions, not only do we need to enhance the methods of the aggregation.Builder constructor, but also support the construction of individual operators through functions in builder/aggregation/bson_build.go and builder/aggregation/bson_build_without_key.go.

Note: Aggregate pipeline operators need to be managed by type. For example Add operator belongs to the Arithmetic Expression Operators, you should add the method of build Add operator in builder/aggregation/arithmetic_builder.go.


考虑到聚合操作分为聚合管道阶段和表达式,go-mongox 分别提供了 aggregation.StageBuilderaggregation.Builder 两种构建器:

  • 对于聚合管道阶段,需要完善 aggregation.StageBuilder 构造器的方法,增加所缺少的聚合管道阶段构建方法。相关信息可参考 Aggregation Pipeline

  • 对于聚合管道表达式,不仅要完善 aggregation.Builder 构造器的方法,还需在 builder/aggregation/bson_build.gobuilder/aggregation/bson_build_without_key.go 中支持构建单个操作符的函数。相关信息可参考 Aggregation Operators

注意:聚合管道操作符需要根据类型划分进行管理。例如 Add 操作符属于算术表达式运算符(Arithmetic Expression Operators),你应该在 builder/aggregation/arithmetic_builder.go 中添加该操作符的构建方法。

其它 | Others

Due to the large number of MongoDB aggregation pipeline stages and operators, it is recommended to implement these features in phases to ensure manageability and reviewability. Each pull request (PR) should include the implementation of multiple stages or operators, except in special cases where a single PR might focus on one stage or operator.

Contribution Guide


由于 MongoDB 的聚合管道阶段和聚合操作符有很多个,建议分批实现这些功能以确保管理和审查的可行性。每次提交的 PR 应包括多个阶段或操作符的实现,避免一个 PR 实现一个阶段或操作符(特殊情况除外)。

贡献指南

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions