-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.go
47 lines (45 loc) · 1.84 KB
/
pipeline.go
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package mongoutils
import (
"go.mongodb.org/mongo-driver/mongo"
)
// MongoPipeline mongo pipeline (mongo.Pipeline) builder
type MongoPipeline interface {
// Add add new Doc
Add(cb func(d MongoDoc) MongoDoc) MongoPipeline
// Match add $match stage. skip nil input
Match(filters any) MongoPipeline
// In add $in stage
In(key string, v any) MongoPipeline
// Limit add $limit stage (ignore negative and zero value)
Limit(limit int64) MongoPipeline
// Skip add $skip stage (ignore negative and zero value)
Skip(skip int64) MongoPipeline
// Sort add $sort stage (ignore nil value)
Sort(sorts any) MongoPipeline
// Unwind add $unwind stage
Unwind(path string, prevNullAndEmpty bool) MongoPipeline
// Lookup add $lookup stage
Lookup(from string, local string, foreign string, as string) MongoPipeline
// Unwrap get first item of array and insert to doc using $addFields stage
Unwrap(field string, as string) MongoPipeline
// LoadRelation load related document using $lookup and $addField
LoadRelation(from string, local string, foreign string, as string) MongoPipeline
// Group add $group stage
Group(cb func(d MongoDoc) MongoDoc) MongoPipeline
// ReplaceRoot add $replaceRoot stage
ReplaceRoot(v any) MongoPipeline
// MergeRoot add $replaceRoot stage with $mergeObjects operator
MergeRoot(fields ...any) MongoPipeline
// UnProject generate $project stage to remove fields from result
UnProject(fields ...string) MongoPipeline
// Project add $project stage. skip nil input
Project(projects any) MongoPipeline
// Deleted generate match for not soft deleted models (deleted_at == nil)
Deleted() MongoPipeline
// Trashes generate match for soft deleted models (deleted_at != nil)
Trashes() MongoPipeline
// NotBackedUp generate match query for not backed up records
NotBackedUp() MongoPipeline
// Build generate mongo pipeline
Build() mongo.Pipeline
}