Skip to content

Commit 82f517f

Browse files
committed
GODRIVER-1810 error when maps with multiple keys are used for ordered… (#558)
1 parent 0271cb9 commit 82f517f

21 files changed

+466
-106
lines changed

mongo/bulk_write.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (bw *bulkWrite) runDelete(ctx context.Context, batch bulkWriteBatch) (opera
248248
func createDeleteDoc(filter interface{}, collation *options.Collation, hint interface{}, deleteOne bool,
249249
registry *bsoncodec.Registry) (bsoncore.Document, error) {
250250

251-
f, err := transformBsoncoreDocument(registry, filter)
251+
f, err := transformBsoncoreDocument(registry, filter, true, "filter")
252252
if err != nil {
253253
return nil, err
254254
}
@@ -264,7 +264,7 @@ func createDeleteDoc(filter interface{}, collation *options.Collation, hint inte
264264
doc = bsoncore.AppendDocumentElement(doc, "collation", collation.ToDocument())
265265
}
266266
if hint != nil {
267-
hintVal, err := transformValue(registry, hint)
267+
hintVal, err := transformValue(registry, hint, false, "hint")
268268
if err != nil {
269269
return nil, err
270270
}
@@ -339,7 +339,7 @@ func createUpdateDoc(
339339
checkDollarKey bool,
340340
registry *bsoncodec.Registry,
341341
) (bsoncore.Document, error) {
342-
f, err := transformBsoncoreDocument(registry, filter)
342+
f, err := transformBsoncoreDocument(registry, filter, true, "filter")
343343
if err != nil {
344344
return nil, err
345345
}
@@ -375,7 +375,7 @@ func createUpdateDoc(
375375
}
376376

377377
if hint != nil {
378-
hintVal, err := transformValue(registry, hint)
378+
hintVal, err := transformValue(registry, hint, false, "hint")
379379
if err != nil {
380380
return nil, err
381381
}

mongo/bulk_write_models.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ func (dom *DeleteOneModel) SetCollation(collation *options.Collation) *DeleteOne
7070
// specification as a document. This option is only valid for MongoDB versions >= 4.4. Server versions >= 3.4 will
7171
// return an error if this option is specified. For server versions < 3.4, the driver will return a client-side error if
7272
// this option is specified. The driver will return an error if this option is specified during an unacknowledged write
73-
// operation. The default value is nil, which means that no hint will be sent.
73+
// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, which
74+
// means that no hint will be sent.
7475
func (dom *DeleteOneModel) SetHint(hint interface{}) *DeleteOneModel {
7576
dom.Hint = hint
7677
return dom
@@ -108,7 +109,8 @@ func (dmm *DeleteManyModel) SetCollation(collation *options.Collation) *DeleteMa
108109
// specification as a document. This option is only valid for MongoDB versions >= 4.4. Server versions >= 3.4 will
109110
// return an error if this option is specified. For server versions < 3.4, the driver will return a client-side error if
110111
// this option is specified. The driver will return an error if this option is specified during an unacknowledged write
111-
// operation. The default value is nil, which means that no hint will be sent.
112+
// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, which
113+
// means that no hint will be sent.
112114
func (dmm *DeleteManyModel) SetHint(hint interface{}) *DeleteManyModel {
113115
dmm.Hint = hint
114116
return dmm
@@ -134,7 +136,8 @@ func NewReplaceOneModel() *ReplaceOneModel {
134136
// specification as a document. This option is only valid for MongoDB versions >= 4.2. Server versions >= 3.4 will
135137
// return an error if this option is specified. For server versions < 3.4, the driver will return a client-side error if
136138
// this option is specified. The driver will return an error if this option is specified during an unacknowledged write
137-
// operation. The default value is nil, which means that no hint will be sent.
139+
// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, which
140+
// means that no hint will be sent.
138141
func (rom *ReplaceOneModel) SetHint(hint interface{}) *ReplaceOneModel {
139142
rom.Hint = hint
140143
return rom
@@ -191,7 +194,8 @@ func NewUpdateOneModel() *UpdateOneModel {
191194
// specification as a document. This option is only valid for MongoDB versions >= 4.2. Server versions >= 3.4 will
192195
// return an error if this option is specified. For server versions < 3.4, the driver will return a client-side error if
193196
// this option is specified. The driver will return an error if this option is specified during an unacknowledged write
194-
// operation. The default value is nil, which means that no hint will be sent.
197+
// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, which
198+
// means that no hint will be sent.
195199
func (uom *UpdateOneModel) SetHint(hint interface{}) *UpdateOneModel {
196200
uom.Hint = hint
197201
return uom
@@ -255,7 +259,8 @@ func NewUpdateManyModel() *UpdateManyModel {
255259
// specification as a document. This option is only valid for MongoDB versions >= 4.2. Server versions >= 3.4 will
256260
// return an error if this option is specified. For server versions < 3.4, the driver will return a client-side error if
257261
// this option is specified. The driver will return an error if this option is specified during an unacknowledged write
258-
// operation. The default value is nil, which means that no hint will be sent.
262+
// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, which
263+
// means that no hint will be sent.
259264
func (umm *UpdateManyModel) SetHint(hint interface{}) *UpdateManyModel {
260265
umm.Hint = hint
261266
return umm

mongo/change_stream.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ func (cs *ChangeStream) buildPipelineSlice(pipeline interface{}) error {
343343

344344
for i := 0; i < val.Len(); i++ {
345345
var elem []byte
346-
elem, cs.err = transformBsoncoreDocument(cs.registry, val.Index(i).Interface())
346+
elem, cs.err = transformBsoncoreDocument(cs.registry, val.Index(i).Interface(), true, fmt.Sprintf("pipeline stage :%v", i))
347347
if cs.err != nil {
348348
return cs.err
349349
}
@@ -367,7 +367,7 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
367367

368368
if cs.options.ResumeAfter != nil {
369369
var raDoc bsoncore.Document
370-
raDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.ResumeAfter)
370+
raDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.ResumeAfter, true, "resumeAfter")
371371
if cs.err != nil {
372372
return nil
373373
}
@@ -377,7 +377,7 @@ func (cs *ChangeStream) createPipelineOptionsDoc() bsoncore.Document {
377377

378378
if cs.options.StartAfter != nil {
379379
var saDoc bsoncore.Document
380-
saDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.StartAfter)
380+
saDoc, cs.err = transformBsoncoreDocument(cs.registry, cs.options.StartAfter, true, "startAfter")
381381
if cs.err != nil {
382382
return nil
383383
}

mongo/client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,13 @@ func (c *Client) configureCrypt(opts *options.AutoEncryptionOptions) error {
649649
// convert schemas in SchemaMap to bsoncore documents
650650
cryptSchemaMap := make(map[string]bsoncore.Document)
651651
for k, v := range opts.SchemaMap {
652-
schema, err := transformBsoncoreDocument(c.registry, v)
652+
schema, err := transformBsoncoreDocument(c.registry, v, true, "schemaMap")
653653
if err != nil {
654654
return err
655655
}
656656
cryptSchemaMap[k] = schema
657657
}
658-
kmsProviders, err := transformBsoncoreDocument(c.registry, opts.KmsProviders)
658+
kmsProviders, err := transformBsoncoreDocument(c.registry, opts.KmsProviders, true, "kmsProviders")
659659
if err != nil {
660660
return fmt.Errorf("error creating KMS providers document: %v", err)
661661
}
@@ -723,7 +723,7 @@ func (c *Client) ListDatabases(ctx context.Context, filter interface{}, opts ...
723723
return ListDatabasesResult{}, err
724724
}
725725

726-
filterDoc, err := transformBsoncoreDocument(c.registry, filter)
726+
filterDoc, err := transformBsoncoreDocument(c.registry, filter, true, "filter")
727727
if err != nil {
728728
return ListDatabasesResult{}, err
729729
}

mongo/client_encryption.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewClientEncryption(keyVaultClient *Client, opts ...*options.ClientEncrypti
4242
db, coll := splitNamespace(ceo.KeyVaultNamespace)
4343
ce.keyVaultColl = ce.keyVaultClient.Database(db).Collection(coll, keyVaultCollOpts)
4444

45-
kmsProviders, err := transformBsoncoreDocument(bson.DefaultRegistry, ceo.KmsProviders)
45+
kmsProviders, err := transformBsoncoreDocument(bson.DefaultRegistry, ceo.KmsProviders, true, "kmsProviders")
4646
if err != nil {
4747
return nil, fmt.Errorf("error creating KMS providers map: %v", err)
4848
}
@@ -69,7 +69,7 @@ func (ce *ClientEncryption) CreateDataKey(ctx context.Context, kmsProvider strin
6969
dko := options.MergeDataKeyOptions(opts...)
7070
co := cryptOpts.DataKey().SetKeyAltNames(dko.KeyAltNames)
7171
if dko.MasterKey != nil {
72-
keyDoc, err := transformBsoncoreDocument(ce.keyVaultClient.registry, dko.MasterKey)
72+
keyDoc, err := transformBsoncoreDocument(ce.keyVaultClient.registry, dko.MasterKey, true, "masterKey")
7373
if err != nil {
7474
return primitive.Binary{}, err
7575
}

mongo/collection.go

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ func (coll *Collection) delete(ctx context.Context, filter interface{}, deleteOn
398398
ctx = context.Background()
399399
}
400400

401-
f, err := transformBsoncoreDocument(coll.registry, filter)
401+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
402402
if err != nil {
403403
return nil, err
404404
}
@@ -439,7 +439,7 @@ func (coll *Collection) delete(ctx context.Context, filter interface{}, deleteOn
439439
doc = bsoncore.AppendDocumentElement(doc, "collation", do.Collation.ToDocument())
440440
}
441441
if do.Hint != nil {
442-
hint, err := transformValue(coll.registry, do.Hint)
442+
hint, err := transformValue(coll.registry, do.Hint, false, "hint")
443443
if err != nil {
444444
return nil, err
445445
}
@@ -623,7 +623,7 @@ func (coll *Collection) UpdateOne(ctx context.Context, filter interface{}, updat
623623
ctx = context.Background()
624624
}
625625

626-
f, err := transformBsoncoreDocument(coll.registry, filter)
626+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
627627
if err != nil {
628628
return nil, err
629629
}
@@ -651,7 +651,7 @@ func (coll *Collection) UpdateMany(ctx context.Context, filter interface{}, upda
651651
ctx = context.Background()
652652
}
653653

654-
f, err := transformBsoncoreDocument(coll.registry, filter)
654+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
655655
if err != nil {
656656
return nil, err
657657
}
@@ -679,12 +679,12 @@ func (coll *Collection) ReplaceOne(ctx context.Context, filter interface{},
679679
ctx = context.Background()
680680
}
681681

682-
f, err := transformBsoncoreDocument(coll.registry, filter)
682+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
683683
if err != nil {
684684
return nil, err
685685
}
686686

687-
r, err := transformBsoncoreDocument(coll.registry, replacement)
687+
r, err := transformBsoncoreDocument(coll.registry, replacement, true, "replacement")
688688
if err != nil {
689689
return nil, err
690690
}
@@ -827,7 +827,7 @@ func aggregate(a aggregateParams) (*Cursor, error) {
827827
op.Comment(*ao.Comment)
828828
}
829829
if ao.Hint != nil {
830-
hintVal, err := transformValue(a.registry, ao.Hint)
830+
hintVal, err := transformValue(a.registry, ao.Hint, false, "hint")
831831
if err != nil {
832832
closeImplicitSession(sess)
833833
return nil, err
@@ -909,7 +909,7 @@ func (coll *Collection) CountDocuments(ctx context.Context, filter interface{},
909909
op.MaxTimeMS(int64(*countOpts.MaxTime / time.Millisecond))
910910
}
911911
if countOpts.Hint != nil {
912-
hintVal, err := transformValue(coll.registry, countOpts.Hint)
912+
hintVal, err := transformValue(coll.registry, countOpts.Hint, false, "hint")
913913
if err != nil {
914914
return 0, err
915915
}
@@ -1017,7 +1017,7 @@ func (coll *Collection) Distinct(ctx context.Context, fieldName string, filter i
10171017
ctx = context.Background()
10181018
}
10191019

1020-
f, err := transformBsoncoreDocument(coll.registry, filter)
1020+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
10211021
if err != nil {
10221022
return nil, err
10231023
}
@@ -1106,7 +1106,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
11061106
ctx = context.Background()
11071107
}
11081108

1109-
f, err := transformBsoncoreDocument(coll.registry, filter)
1109+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
11101110
if err != nil {
11111111
return nil, err
11121112
}
@@ -1170,7 +1170,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
11701170
}
11711171
}
11721172
if fo.Hint != nil {
1173-
hint, err := transformValue(coll.registry, fo.Hint)
1173+
hint, err := transformValue(coll.registry, fo.Hint, false, "hint")
11741174
if err != nil {
11751175
closeImplicitSession(sess)
11761176
return nil, err
@@ -1187,7 +1187,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
11871187
op.Limit(limit)
11881188
}
11891189
if fo.Max != nil {
1190-
max, err := transformBsoncoreDocument(coll.registry, fo.Max)
1190+
max, err := transformBsoncoreDocument(coll.registry, fo.Max, true, "max")
11911191
if err != nil {
11921192
closeImplicitSession(sess)
11931193
return nil, err
@@ -1201,7 +1201,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
12011201
op.MaxTimeMS(int64(*fo.MaxTime / time.Millisecond))
12021202
}
12031203
if fo.Min != nil {
1204-
min, err := transformBsoncoreDocument(coll.registry, fo.Min)
1204+
min, err := transformBsoncoreDocument(coll.registry, fo.Min, true, "min")
12051205
if err != nil {
12061206
closeImplicitSession(sess)
12071207
return nil, err
@@ -1215,7 +1215,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
12151215
op.OplogReplay(*fo.OplogReplay)
12161216
}
12171217
if fo.Projection != nil {
1218-
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection)
1218+
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection, true, "projection")
12191219
if err != nil {
12201220
closeImplicitSession(sess)
12211221
return nil, err
@@ -1235,7 +1235,7 @@ func (coll *Collection) Find(ctx context.Context, filter interface{},
12351235
op.Snapshot(*fo.Snapshot)
12361236
}
12371237
if fo.Sort != nil {
1238-
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort)
1238+
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort, false, "sort")
12391239
if err != nil {
12401240
closeImplicitSession(sess)
12411241
return nil, err
@@ -1376,7 +1376,7 @@ func (coll *Collection) findAndModify(ctx context.Context, op *operation.FindAnd
13761376
func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{},
13771377
opts ...*options.FindOneAndDeleteOptions) *SingleResult {
13781378

1379-
f, err := transformBsoncoreDocument(coll.registry, filter)
1379+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
13801380
if err != nil {
13811381
return &SingleResult{err: err}
13821382
}
@@ -1389,21 +1389,21 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}
13891389
op = op.MaxTimeMS(int64(*fod.MaxTime / time.Millisecond))
13901390
}
13911391
if fod.Projection != nil {
1392-
proj, err := transformBsoncoreDocument(coll.registry, fod.Projection)
1392+
proj, err := transformBsoncoreDocument(coll.registry, fod.Projection, true, "projection")
13931393
if err != nil {
13941394
return &SingleResult{err: err}
13951395
}
13961396
op = op.Fields(proj)
13971397
}
13981398
if fod.Sort != nil {
1399-
sort, err := transformBsoncoreDocument(coll.registry, fod.Sort)
1399+
sort, err := transformBsoncoreDocument(coll.registry, fod.Sort, false, "sort")
14001400
if err != nil {
14011401
return &SingleResult{err: err}
14021402
}
14031403
op = op.Sort(sort)
14041404
}
14051405
if fod.Hint != nil {
1406-
hint, err := transformValue(coll.registry, fod.Hint)
1406+
hint, err := transformValue(coll.registry, fod.Hint, false, "hint")
14071407
if err != nil {
14081408
return &SingleResult{err: err}
14091409
}
@@ -1430,11 +1430,11 @@ func (coll *Collection) FindOneAndDelete(ctx context.Context, filter interface{}
14301430
func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{},
14311431
replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *SingleResult {
14321432

1433-
f, err := transformBsoncoreDocument(coll.registry, filter)
1433+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
14341434
if err != nil {
14351435
return &SingleResult{err: err}
14361436
}
1437-
r, err := transformBsoncoreDocument(coll.registry, replacement)
1437+
r, err := transformBsoncoreDocument(coll.registry, replacement, true, "replacement")
14381438
if err != nil {
14391439
return &SingleResult{err: err}
14401440
}
@@ -1454,7 +1454,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{
14541454
op = op.MaxTimeMS(int64(*fo.MaxTime / time.Millisecond))
14551455
}
14561456
if fo.Projection != nil {
1457-
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection)
1457+
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection, true, "projection")
14581458
if err != nil {
14591459
return &SingleResult{err: err}
14601460
}
@@ -1464,7 +1464,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{
14641464
op = op.NewDocument(*fo.ReturnDocument == options.After)
14651465
}
14661466
if fo.Sort != nil {
1467-
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort)
1467+
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort, false, "sort")
14681468
if err != nil {
14691469
return &SingleResult{err: err}
14701470
}
@@ -1474,7 +1474,7 @@ func (coll *Collection) FindOneAndReplace(ctx context.Context, filter interface{
14741474
op = op.Upsert(*fo.Upsert)
14751475
}
14761476
if fo.Hint != nil {
1477-
hint, err := transformValue(coll.registry, fo.Hint)
1477+
hint, err := transformValue(coll.registry, fo.Hint, false, "hint")
14781478
if err != nil {
14791479
return &SingleResult{err: err}
14801480
}
@@ -1506,7 +1506,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
15061506
ctx = context.Background()
15071507
}
15081508

1509-
f, err := transformBsoncoreDocument(coll.registry, filter)
1509+
f, err := transformBsoncoreDocument(coll.registry, filter, true, "filter")
15101510
if err != nil {
15111511
return &SingleResult{err: err}
15121512
}
@@ -1537,7 +1537,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
15371537
op = op.MaxTimeMS(int64(*fo.MaxTime / time.Millisecond))
15381538
}
15391539
if fo.Projection != nil {
1540-
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection)
1540+
proj, err := transformBsoncoreDocument(coll.registry, fo.Projection, true, "projection")
15411541
if err != nil {
15421542
return &SingleResult{err: err}
15431543
}
@@ -1547,7 +1547,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
15471547
op = op.NewDocument(*fo.ReturnDocument == options.After)
15481548
}
15491549
if fo.Sort != nil {
1550-
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort)
1550+
sort, err := transformBsoncoreDocument(coll.registry, fo.Sort, false, "sort")
15511551
if err != nil {
15521552
return &SingleResult{err: err}
15531553
}
@@ -1557,7 +1557,7 @@ func (coll *Collection) FindOneAndUpdate(ctx context.Context, filter interface{}
15571557
op = op.Upsert(*fo.Upsert)
15581558
}
15591559
if fo.Hint != nil {
1560-
hint, err := transformValue(coll.registry, fo.Hint)
1560+
hint, err := transformValue(coll.registry, fo.Hint, false, "hint")
15611561
if err != nil {
15621562
return &SingleResult{err: err}
15631563
}

0 commit comments

Comments
 (0)