Skip to content

Commit 4917210

Browse files
committed
all: update to sync with MongoDB Go driver
Reported by @PikBot, the MongoDB Go driver was changed with mongodb/mongo-go-driver@6fd340f but unfortunately we hadn't made those updates either. This change fixes that. Fixes #7
1 parent fdc8625 commit 4917210

5 files changed

Lines changed: 72 additions & 74 deletions

File tree

mongo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ import (
1818
"context"
1919

2020
"github.com/mongodb/mongo-go-driver/mongo"
21-
"github.com/mongodb/mongo-go-driver/mongo/clientopt"
21+
"github.com/mongodb/mongo-go-driver/mongo/options"
2222
)
2323

24-
func Connect(ctx context.Context, uri string, opts ...clientopt.Option) (*WrappedClient, error) {
24+
func Connect(ctx context.Context, uri string, opts ...*options.ClientOptions) (*WrappedClient, error) {
2525
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Connect")
2626
defer span.end(ctx)
2727

wrapped_client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,10 @@ package mongowrapper
1717
import (
1818
"context"
1919

20-
"github.com/mongodb/mongo-go-driver/core/readpref"
21-
"github.com/mongodb/mongo-go-driver/core/session"
2220
"github.com/mongodb/mongo-go-driver/mongo"
23-
"github.com/mongodb/mongo-go-driver/mongo/dbopt"
24-
"github.com/mongodb/mongo-go-driver/mongo/listdbopt"
25-
"github.com/mongodb/mongo-go-driver/mongo/sessionopt"
21+
"github.com/mongodb/mongo-go-driver/mongo/options"
22+
"github.com/mongodb/mongo-go-driver/mongo/readpref"
23+
"github.com/mongodb/mongo-go-driver/x/mongo/driver/session"
2624
)
2725

2826
type WrappedClient struct {
@@ -50,7 +48,7 @@ func (wc *WrappedClient) Connect(ctx context.Context) error {
5048

5149
func (wc *WrappedClient) ConnectionString() string { return wc.cc.ConnectionString() }
5250

53-
func (wc *WrappedClient) Database(name string, opts ...dbopt.Option) *WrappedDatabase {
51+
func (wc *WrappedClient) Database(name string, opts ...*options.DatabaseOptions) *WrappedDatabase {
5452
db := wc.cc.Database(name, opts...)
5553
if db == nil {
5654
return nil
@@ -69,7 +67,7 @@ func (wc *WrappedClient) Disconnect(ctx context.Context) error {
6967
return err
7068
}
7169

72-
func (wc *WrappedClient) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) ([]string, error) {
70+
func (wc *WrappedClient) ListDatabaseNames(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) ([]string, error) {
7371
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Client.ListDatabaseNames")
7472
defer span.end(ctx)
7573

@@ -80,7 +78,7 @@ func (wc *WrappedClient) ListDatabaseNames(ctx context.Context, filter interface
8078
return dbs, err
8179
}
8280

83-
func (wc *WrappedClient) ListDatabases(ctx context.Context, filter interface{}, opts ...listdbopt.ListDatabases) (mongo.ListDatabasesResult, error) {
81+
func (wc *WrappedClient) ListDatabases(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) (mongo.ListDatabasesResult, error) {
8482
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Client.ListDatabases")
8583
defer span.end(ctx)
8684

@@ -102,15 +100,19 @@ func (wc *WrappedClient) Ping(ctx context.Context, rp *readpref.ReadPref) error
102100
return err
103101
}
104102

105-
func (wc *WrappedClient) StartSession(opts ...sessionopt.Session) (mongo.Session, error) {
106-
return wc.cc.StartSession(opts...)
103+
func (wc *WrappedClient) StartSession(opts ...*options.SessionOptions) (mongo.Session, error) {
104+
ss, err := wc.cc.StartSession(opts...)
105+
if err != nil {
106+
return nil, err
107+
}
108+
return &WrappedSession{Session: ss}, nil
107109
}
108110

109111
func (wc *WrappedClient) UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error {
110112
return wc.cc.UseSession(ctx, fn)
111113
}
112114

113-
func (wc *WrappedClient) UseSessionWithOptions(ctx context.Context, opts []sessionopt.Session, fn func(mongo.SessionContext) error) error {
115+
func (wc *WrappedClient) UseSessionWithOptions(ctx context.Context, opts *options.SessionOptions, fn func(mongo.SessionContext) error) error {
114116
return wc.cc.UseSessionWithOptions(ctx, opts, fn)
115117
}
116118

wrapped_collection.go

Lines changed: 23 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,14 @@ import (
1818
"context"
1919

2020
"github.com/mongodb/mongo-go-driver/mongo"
21-
"github.com/mongodb/mongo-go-driver/mongo/aggregateopt"
22-
"github.com/mongodb/mongo-go-driver/mongo/bulkwriteopt"
23-
"github.com/mongodb/mongo-go-driver/mongo/changestreamopt"
24-
"github.com/mongodb/mongo-go-driver/mongo/collectionopt"
25-
"github.com/mongodb/mongo-go-driver/mongo/countopt"
26-
"github.com/mongodb/mongo-go-driver/mongo/deleteopt"
27-
"github.com/mongodb/mongo-go-driver/mongo/distinctopt"
28-
"github.com/mongodb/mongo-go-driver/mongo/dropcollopt"
29-
"github.com/mongodb/mongo-go-driver/mongo/findopt"
30-
"github.com/mongodb/mongo-go-driver/mongo/insertopt"
31-
"github.com/mongodb/mongo-go-driver/mongo/replaceopt"
32-
"github.com/mongodb/mongo-go-driver/mongo/updateopt"
21+
"github.com/mongodb/mongo-go-driver/mongo/options"
3322
)
3423

3524
type WrappedCollection struct {
3625
coll *mongo.Collection
3726
}
3827

39-
func (wc *WrappedCollection) Aggregate(ctx context.Context, pipeline interface{}, opts ...aggregateopt.Aggregate) (mongo.Cursor, error) {
28+
func (wc *WrappedCollection) Aggregate(ctx context.Context, pipeline interface{}, opts ...*options.AggregateOptions) (mongo.Cursor, error) {
4029
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Aggregate")
4130
defer span.end(ctx)
4231

@@ -47,7 +36,7 @@ func (wc *WrappedCollection) Aggregate(ctx context.Context, pipeline interface{}
4736
return cur, err
4837
}
4938

50-
func (wc *WrappedCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...bulkwriteopt.BulkWrite) (*mongo.BulkWriteResult, error) {
39+
func (wc *WrappedCollection) BulkWrite(ctx context.Context, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error) {
5140
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.BulkWrite")
5241
defer span.end(ctx)
5342

@@ -58,11 +47,11 @@ func (wc *WrappedCollection) BulkWrite(ctx context.Context, models []mongo.Write
5847
return bwres, err
5948
}
6049

61-
func (wc *WrappedCollection) Clone(opts ...collectionopt.Option) (*mongo.Collection, error) {
50+
func (wc *WrappedCollection) Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error) {
6251
return wc.coll.Clone(opts...)
6352
}
6453

65-
func (wc *WrappedCollection) Count(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error) {
54+
func (wc *WrappedCollection) Count(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) {
6655
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Count")
6756
defer span.end(ctx)
6857

@@ -73,7 +62,7 @@ func (wc *WrappedCollection) Count(ctx context.Context, filter interface{}, opts
7362
return count, err
7463
}
7564

76-
func (wc *WrappedCollection) CountDocuments(ctx context.Context, filter interface{}, opts ...countopt.Count) (int64, error) {
65+
func (wc *WrappedCollection) CountDocuments(ctx context.Context, filter interface{}, opts ...*options.CountOptions) (int64, error) {
7766
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.CountDocuments")
7867
defer span.end(ctx)
7968

@@ -86,7 +75,7 @@ func (wc *WrappedCollection) CountDocuments(ctx context.Context, filter interfac
8675

8776
func (wc *WrappedCollection) Database() *mongo.Database { return wc.coll.Database() }
8877

89-
func (wc *WrappedCollection) DeleteMany(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*mongo.DeleteResult, error) {
78+
func (wc *WrappedCollection) DeleteMany(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) {
9079
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.DeleteMany")
9180
defer span.end(ctx)
9281

@@ -97,7 +86,7 @@ func (wc *WrappedCollection) DeleteMany(ctx context.Context, filter interface{},
9786
return dmres, err
9887
}
9988

100-
func (wc *WrappedCollection) DeleteOne(ctx context.Context, filter interface{}, opts ...deleteopt.Delete) (*mongo.DeleteResult, error) {
89+
func (wc *WrappedCollection) DeleteOne(ctx context.Context, filter interface{}, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error) {
10190
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.DeleteOne")
10291
defer span.end(ctx)
10392

@@ -108,7 +97,7 @@ func (wc *WrappedCollection) DeleteOne(ctx context.Context, filter interface{},
10897
return dor, err
10998
}
11099

111-
func (wc *WrappedCollection) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...distinctopt.Distinct) ([]interface{}, error) {
100+
func (wc *WrappedCollection) Distinct(ctx context.Context, fieldName string, filter interface{}, opts ...*options.DistinctOptions) ([]interface{}, error) {
112101
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Distinct")
113102
defer span.end(ctx)
114103

@@ -119,18 +108,18 @@ func (wc *WrappedCollection) Distinct(ctx context.Context, fieldName string, fil
119108
return distinct, err
120109
}
121110

122-
func (wc *WrappedCollection) Drop(ctx context.Context, opts ...dropcollopt.DropColl) error {
111+
func (wc *WrappedCollection) Drop(ctx context.Context) error {
123112
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Drop")
124113
defer span.end(ctx)
125114

126-
err := wc.coll.Drop(ctx, opts...)
115+
err := wc.coll.Drop(ctx)
127116
if err != nil {
128117
span.setError(err)
129118
}
130119
return err
131120
}
132121

133-
func (wc *WrappedCollection) EstimatedDocumentCount(ctx context.Context, opts ...countopt.EstimatedDocumentCount) (int64, error) {
122+
func (wc *WrappedCollection) EstimatedDocumentCount(ctx context.Context, opts ...*options.EstimatedDocumentCountOptions) (int64, error) {
134123
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.EstimatedDocumentCount")
135124
defer span.end(ctx)
136125

@@ -141,7 +130,7 @@ func (wc *WrappedCollection) EstimatedDocumentCount(ctx context.Context, opts ..
141130
return count, err
142131
}
143132

144-
func (wc *WrappedCollection) Find(ctx context.Context, filter interface{}, opts ...findopt.Find) (mongo.Cursor, error) {
133+
func (wc *WrappedCollection) Find(ctx context.Context, filter interface{}, opts ...*options.FindOptions) (mongo.Cursor, error) {
145134
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Find")
146135
defer span.end(ctx)
147136

@@ -152,28 +141,28 @@ func (wc *WrappedCollection) Find(ctx context.Context, filter interface{}, opts
152141
return cur, err
153142
}
154143

155-
func (wc *WrappedCollection) FindOne(ctx context.Context, filter interface{}, opts ...findopt.One) *mongo.DocumentResult {
144+
func (wc *WrappedCollection) FindOne(ctx context.Context, filter interface{}, opts ...*options.FindOneOptions) *mongo.SingleResult {
156145
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.FindOne")
157146
defer span.end(ctx)
158147

159148
return wc.coll.FindOne(ctx, filter, opts...)
160149
}
161150

162-
func (wc *WrappedCollection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...findopt.DeleteOne) *mongo.DocumentResult {
151+
func (wc *WrappedCollection) FindOneAndDelete(ctx context.Context, filter interface{}, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult {
163152
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.FindOneAndDelete")
164153
defer span.end(ctx)
165154

166155
return wc.coll.FindOneAndDelete(ctx, filter, opts...)
167156
}
168157

169-
func (wc *WrappedCollection) FindOneAndReplace(ctx context.Context, filter, replacement interface{}, opts ...findopt.ReplaceOne) *mongo.DocumentResult {
158+
func (wc *WrappedCollection) FindOneAndReplace(ctx context.Context, filter, replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult {
170159
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.FindOneAndReplace")
171160
defer span.end(ctx)
172161

173162
return wc.coll.FindOneAndReplace(ctx, filter, replacement, opts...)
174163
}
175164

176-
func (wc *WrappedCollection) FindOneAndUpdate(ctx context.Context, filter, update interface{}, opts ...findopt.UpdateOne) *mongo.DocumentResult {
165+
func (wc *WrappedCollection) FindOneAndUpdate(ctx context.Context, filter, update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult {
177166
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.FindOneAndUpdate")
178167
defer span.end(ctx)
179168

@@ -182,7 +171,7 @@ func (wc *WrappedCollection) FindOneAndUpdate(ctx context.Context, filter, updat
182171

183172
func (wc *WrappedCollection) Indexes() mongo.IndexView { return wc.coll.Indexes() }
184173

185-
func (wc *WrappedCollection) InsertMany(ctx context.Context, documents []interface{}, opts ...insertopt.Many) (*mongo.InsertManyResult, error) {
174+
func (wc *WrappedCollection) InsertMany(ctx context.Context, documents []interface{}, opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error) {
186175
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.InsertMany")
187176
defer span.end(ctx)
188177

@@ -193,7 +182,7 @@ func (wc *WrappedCollection) InsertMany(ctx context.Context, documents []interfa
193182
return insmres, err
194183
}
195184

196-
func (wc *WrappedCollection) InsertOne(ctx context.Context, document interface{}, opts ...insertopt.One) (*mongo.InsertOneResult, error) {
185+
func (wc *WrappedCollection) InsertOne(ctx context.Context, document interface{}, opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error) {
197186
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.InsertOne")
198187
defer span.end(ctx)
199188

@@ -206,7 +195,7 @@ func (wc *WrappedCollection) InsertOne(ctx context.Context, document interface{}
206195

207196
func (wc *WrappedCollection) Name() string { return wc.coll.Name() }
208197

209-
func (wc *WrappedCollection) ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...replaceopt.Replace) (*mongo.UpdateResult, error) {
198+
func (wc *WrappedCollection) ReplaceOne(ctx context.Context, filter, replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error) {
210199
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.ReplaceOne")
211200
defer span.end(ctx)
212201

@@ -217,7 +206,7 @@ func (wc *WrappedCollection) ReplaceOne(ctx context.Context, filter, replacement
217206
return repres, err
218207
}
219208

220-
func (wc *WrappedCollection) UpdateMany(ctx context.Context, filter, replacement interface{}, opts ...updateopt.Update) (*mongo.UpdateResult, error) {
209+
func (wc *WrappedCollection) UpdateMany(ctx context.Context, filter, replacement interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
221210
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.UpdateMany")
222211
defer span.end(ctx)
223212

@@ -228,7 +217,7 @@ func (wc *WrappedCollection) UpdateMany(ctx context.Context, filter, replacement
228217
return umres, err
229218
}
230219

231-
func (wc *WrappedCollection) UpdateOne(ctx context.Context, filter, replacement interface{}, opts ...updateopt.Update) (*mongo.UpdateResult, error) {
220+
func (wc *WrappedCollection) UpdateOne(ctx context.Context, filter, replacement interface{}, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error) {
232221
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.UpdateOne")
233222
defer span.end(ctx)
234223

@@ -239,7 +228,7 @@ func (wc *WrappedCollection) UpdateOne(ctx context.Context, filter, replacement
239228
return uores, err
240229
}
241230

242-
func (wc *WrappedCollection) Watch(ctx context.Context, pipeline interface{}, opts ...changestreamopt.ChangeStream) (mongo.Cursor, error) {
231+
func (wc *WrappedCollection) Watch(ctx context.Context, pipeline interface{}, opts ...*options.ChangeStreamOptions) (mongo.Cursor, error) {
243232
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Collection.Watch")
244233
defer span.end(ctx)
245234

wrapped_database.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ import (
1818
"context"
1919
"sync"
2020

21-
"github.com/mongodb/mongo-go-driver/bson"
22-
"github.com/mongodb/mongo-go-driver/core/readconcern"
23-
"github.com/mongodb/mongo-go-driver/core/readpref"
24-
"github.com/mongodb/mongo-go-driver/core/writeconcern"
2521
"github.com/mongodb/mongo-go-driver/mongo"
26-
"github.com/mongodb/mongo-go-driver/mongo/collectionopt"
27-
"github.com/mongodb/mongo-go-driver/mongo/dbopt"
28-
"github.com/mongodb/mongo-go-driver/mongo/listcollectionopt"
29-
"github.com/mongodb/mongo-go-driver/mongo/runcmdopt"
22+
"github.com/mongodb/mongo-go-driver/mongo/options"
23+
"github.com/mongodb/mongo-go-driver/mongo/readconcern"
24+
"github.com/mongodb/mongo-go-driver/mongo/readpref"
25+
"github.com/mongodb/mongo-go-driver/mongo/writeconcern"
3026
)
3127

3228
type WrappedDatabase struct {
@@ -45,7 +41,7 @@ func (wd *WrappedDatabase) Client() *WrappedClient {
4541
return &WrappedClient{cc: cc}
4642
}
4743

48-
func (wd *WrappedDatabase) Collection(name string, opts ...collectionopt.Option) *WrappedCollection {
44+
func (wd *WrappedDatabase) Collection(name string, opts ...*options.CollectionOptions) *WrappedCollection {
4945
if wd.db == nil {
5046
return nil
5147
}
@@ -56,18 +52,18 @@ func (wd *WrappedDatabase) Collection(name string, opts ...collectionopt.Option)
5652
return &WrappedCollection{coll: coll}
5753
}
5854

59-
func (wd *WrappedDatabase) Drop(ctx context.Context, opts ...dbopt.DropDB) error {
55+
func (wd *WrappedDatabase) Drop(ctx context.Context) error {
6056
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Database.Drop")
6157
defer span.end(ctx)
6258

63-
err := wd.db.Drop(ctx, opts...)
59+
err := wd.db.Drop(ctx)
6460
if err != nil {
6561
span.setError(err)
6662
}
6763
return err
6864
}
6965

70-
func (wd *WrappedDatabase) ListCollections(ctx context.Context, filter *bson.Document, opts ...listcollectionopt.ListCollections) (mongo.Cursor, error) {
66+
func (wd *WrappedDatabase) ListCollections(ctx context.Context, filter interface{}, opts ...*options.ListCollectionsOptions) (mongo.Cursor, error) {
7167
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Database.ListCollections")
7268
defer span.end(ctx)
7369

@@ -82,15 +78,11 @@ func (wd *WrappedDatabase) Name() string { return wd.db
8278
func (wd *WrappedDatabase) ReadConcern() *readconcern.ReadConcern { return wd.db.ReadConcern() }
8379
func (wd *WrappedDatabase) ReadPreference() *readpref.ReadPref { return wd.db.ReadPreference() }
8480

85-
func (wd *WrappedDatabase) RunCommand(ctx context.Context, runCommand interface{}, opts ...runcmdopt.Option) (bson.Raw, error) {
81+
func (wd *WrappedDatabase) RunCommand(ctx context.Context, runCommand interface{}, opts ...*options.RunCmdOptions) *mongo.SingleResult {
8682
ctx, span := roundtripTrackingSpan(ctx, "github.com/mongodb/mongo-go-driver.Database.RunCommand")
8783
defer span.end(ctx)
8884

89-
raw, err := wd.db.RunCommand(ctx, runCommand, opts...)
90-
if err != nil {
91-
span.setError(err)
92-
}
93-
return raw, err
85+
return wd.db.RunCommand(ctx, runCommand, opts...)
9486
}
9587

9688
func (wd *WrappedDatabase) WriteConcern() *writeconcern.WriteConcern { return wd.db.WriteConcern() }

0 commit comments

Comments
 (0)