-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
None
-
Affects Version/s: None
-
Component/s: Aggregation
Defining aggregation pipelines using the Go driver can be a bad experience. The bson.D type (which is frequently used to define agg pipelines) does not provide compile-time safety for types used in aggregation pipelines and the syntax becomes difficult to read quickly as aggregation pipelines become more complex.
Some other drivers, such as Java and .NET, provide helper functions that add a convenience (and sometimes type-safety) layer on top of the aggregation pipeline syntax, significantly improving the developer experience of using aggregation pipelines. Creating helper functions in the Go driver would provide a similar improvement in the experience of using aggregation pipelines in Go.
Creating a comprehensive set of aggregation pipeline helpers is a very large task, so to help improve the experience for the majority of users faster, we should target creating helpers for the most popular aggregation pipelines. The helpers need to be able to interoperate with existing bson.D pipeline declaration logic so that users have the option to use a mixture of pipeline stages defined with the helpers and with bson.D.
Definition of done:
- Create a set of aggregation pipeline helpers that output aggregation pipeline stages.
- Consider using the Java driver aggregation builder as reference.
- The helper must be able to be combined with other aggregation pipeline stages defined as bson.D or bson.M (i.e. allow incrementally replacing pipeline stages defined with bson.D/bson.M with helper calls without replacing the entire pipeline).
- Update all documentation to use the aggregation pipeline helpers instead of bson.D/bson.M where possible.
Open questions:
- Should we create a new package (e.g. aggregate.Match), a new type (e.g. mongo.Aggregate().Match), or something else?
- Should the helper output bson.D or another type? It must be possible to mix helper output with other pipeline stages defined using bson.D/bson.M.
- is related to
-
GODRIVER-2459 Proposal: Improve a way of making filters and aggregation pipilines
- Backlog
- related to
-
GODRIVER-3012 Create a CRUD query filters helper
- Backlog
-
GODRIVER-2271 Update "bson.D" BSON document literal syntax to resolve Go vet linter warnings
- Backlog