-
Notifications
You must be signed in to change notification settings - Fork 3
Aggregate Operation #1
Description
Aggregate Operation
This issue is cover for support MongoDB aggregate operation in Kyte.
Problem
Kyte does not have a wrapper for MongoDB aggregate operation. This is a problem because it limits the ability of the user to perform complex queries on the database.
Solution
We will add support for MongoDB aggregate operation in Kyte. By doing this, we have to still provide our schema validation feature and also have to be easy to use.
Plan
-
Day 1: We have to add most popular aggregate operations such as;
-
Day 2: We have to add support for the rest of the aggregate operations.
We can separate the implementation of each operation into different pull requests to make the review process easier.
Implementation
To do not break the current way of using Kyte, we will add a new method called Aggregate to the kyte. This method will receive a list of stages and will return a mongo.Pipeline and an error.
The Aggregate usage will be like this:
pipeline, err := kyte.
Aggregate().
Match(
kyte.Filter().
Exists("age", true).
GreaterThan("age", 10).
LessThan("age", 20).
Type("name", bson.TypeString),
).
Group(
kyte.UnderScoreIDWithDollar,
kyte.Accumulate().
Push("full_name", bson.M{"$concat": []string{"$name", " ", "$surname"}}),
).
Project(
kyte.Projection().
Include("full_name").
Exclude("name"),
).
Sort(
Ascending("full_name"),
).
Limit(10).
Skip(5).
Unwind("full_name").
Lookup(
"from", "localField", "foreignField", "as",
).
AddFields(
kyte.Fields().
Add("new_field", "value"),
).
Build()Note: Implementation could be different from the example above.