-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaggregate.go
More file actions
25 lines (22 loc) · 894 Bytes
/
Copy pathaggregate.go
File metadata and controls
25 lines (22 loc) · 894 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package morm
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
)
// Aggregate performs an aggregation query on the MongoDB collection using the specified pipeline.
// It takes a pipeline as an interface{}, representing the aggregation stages.
//
// Parameters:
// - pipeline: The interface{} representing the aggregation pipeline stages.
// - ctx: Optional context.Context for the aggregation operation. If not provided, the default context will be used.
//
// Returns:
// - *mongo.Cursor: A cursor pointing to the result of the aggregation query.
// - error: An error if any occurred during the aggregation operation.
func (c *Collect) Aggregate(pipeline interface{}, ctx ...context.Context) (*mongo.Cursor, error) {
var backgroundContext = context.Background()
if len(ctx) > 0 {
backgroundContext = ctx[0]
}
return c.collection.Aggregate(backgroundContext, pipeline)
}