[GODRIVER-2889] Create aggregation pipeline helpers Created: 04/Jul/23  Updated: 11/Oct/23

Status: Backlog
Project: Go Driver
Component/s: Aggregation
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Unknown
Reporter: Matt Dale Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Related
related to GODRIVER-3012 Create a CRUD query filters helper Backlog
related to GODRIVER-2271 Update "bson.D" BSON document literal... Backlog
is related to GODRIVER-2459 Proposal: Improve a way of making fil... Backlog
Quarter: FY24Q3
Documentation Changes Summary:

1. What would you like to communicate to the user about this feature?
2. Would you like the user to see examples of the syntax and/or executable code and its output?
3. Which versions of the driver/connector does this apply to?


 Description   

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.
  • 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.


 Comments   
Comment by Matt Dale [ 10/Jul/23 ]

Additional examples:

Generated at Thu Feb 08 08:39:35 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.