-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwrapped_collection.go
139 lines (95 loc) · 4.96 KB
/
wrapped_collection.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package gomongowrapper
import (
"context"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
tracewrap "github.com/opencensus-integrations/gomongowrapper"
)
type Collection struct {
coll *tracewrap.WrappedCollection
}
func (wc *Collection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (*mongo.Cursor, error) {
cur, err := wc.coll.Aggregate(ctx, pipeline, opts...)
return cur, handle(err)
}
func (wc *Collection) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error) {
bwres, err := wc.coll.BulkWrite(ctx, models, opts...)
return bwres, handle(err)
}
func (wc *Collection) Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error) {
col, err := wc.coll.Clone(opts...)
return col, handle(err)
}
func (wc *Collection) Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) {
count, err := wc.coll.CountDocuments(ctx, filter, opts...)
return count, handle(err)
}
func (wc *Collection) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) {
count, err := wc.coll.CountDocuments(ctx, filter, opts...)
return count, handle(err)
}
func (wc *Collection) Database() *mongo.Database { return wc.coll.Database() }
func (wc *Collection) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) {
dmres, err := wc.coll.DeleteMany(ctx, filter, opts...)
return dmres, handle(err)
}
func (wc *Collection) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) {
dor, err := wc.coll.DeleteOne(ctx, filter, opts...)
return dor, handle(err)
}
func (wc *Collection) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error) {
distinct, err := wc.coll.Distinct(ctx, fieldName, filter, opts...)
return distinct, handle(err)
}
func (wc *Collection) Drop(ctx context.Context) error {
return handle(wc.coll.Drop(ctx))
}
func (wc *Collection) EstimatedDocumentCount(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error) {
count, err := wc.coll.EstimatedDocumentCount(ctx, opts...)
return count, handle(err)
}
func (wc *Collection) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (*mongo.Cursor, error) {
cur, err := wc.coll.Find(ctx, filter, opts...)
return cur, handle(err)
}
func (wc *Collection) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult {
return wc.coll.FindOne(ctx, filter, opts...)
}
func (wc *Collection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult {
return wc.coll.FindOneAndDelete(ctx, filter, opts...)
}
func (wc *Collection) FindOneAndReplace(ctx context.Context, filter, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult {
return wc.coll.FindOneAndReplace(ctx, filter, replacement, opts...)
}
func (wc *Collection) FindOneAndUpdate(ctx context.Context, filter, update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult {
return wc.coll.FindOneAndUpdate(ctx, filter, update, opts...)
}
func (wc *Collection) Indexes() mongo.IndexView { return wc.coll.Indexes() }
func (wc *Collection) InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error) {
insmres, err := wc.coll.InsertMany(ctx, documents, opts...)
return insmres, handle(err)
}
func (wc *Collection) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error) {
insores, err := wc.coll.InsertOne(ctx, document, opts...)
return insores, handle(err)
}
func (wc *Collection) Name() string { return wc.coll.Name() }
func (wc *Collection) ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error) {
repres, err := wc.coll.ReplaceOne(ctx, filter, replacement, opts...)
return repres, handle(err)
}
func (wc *Collection) UpdateMany(ctx context.Context, filter, replacement interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
umres, err := wc.coll.UpdateMany(ctx, filter, replacement, opts...)
return umres, handle(err)
}
func (wc *Collection) UpdateOne(ctx context.Context, filter, replacement interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
uores, err := wc.coll.UpdateOne(ctx, filter, replacement, opts...)
return uores, handle(err)
}
func (wc *Collection) Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error) {
cs, err := wc.coll.Watch(ctx, pipeline, opts...)
return cs, handle(err)
}
func (wc *Collection) Collection() *mongo.Collection {
return wc.coll.Collection()
}