Skip to content

Commit c4d1a72

Browse files
Merge branch 'master' into GODRIVER-3086
2 parents 382b416 + 563588a commit c4d1a72

File tree

35 files changed

+278
-6179
lines changed

35 files changed

+278
-6179
lines changed

docs/migration-2.0.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1183,8 +1183,20 @@ A new `RawArray` type has been added to the `bson` package as a primitive type t
11831183

11841184
### ValueMarshaler
11851185

1186-
The `MarshalBSONValue` method of the `ValueMarshaler` interface is only required to return a byte type value representing the BSON type to avoid importing the `bsontype` package.
1186+
The `MarshalBSONValue` method of the [ValueMarshaler](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueMarshaler) interface now returns a `byte` value representing the [BSON type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type). That allows external packages to implement the `ValueMarshaler` interface without having to import the `bson` package. Convert a returned `byte` value to [bson.Type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type) to compare with the BSON type constants. For example:
1187+
1188+
```go
1189+
btype, _, _ := m.MarshalBSONValue()
1190+
fmt.Println("type of data: %s: ", bson.Type(btype))
1191+
fmt.Println("type of data is an array: %v", bson.Type(btype) == bson.TypeArray)
1192+
```
11871193

11881194
### ValueUnmarshaler
11891195

1190-
The `UnmarshalBSONValue` method of the `ValueUnmarshaler` interface is only required to take a byte type argument representing the BSON type to avoid importing the Go driver package.
1196+
The `UnmarshalBSONValue` method of the [ValueUnmarshaler](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#ValueUnmarshaler) interface now accepts a `byte` value representing the [BSON type](https://pkg.go.dev/go.mongodb.org/mongo-driver/v2/bson#Type) for the first argument. That allows packages to implement `ValueUnmarshaler` without having to import the `bson` package. For example:
1197+
1198+
```go
1199+
if err := m.UnmarshalBSONValue(bson.TypeEmbeddedDocument, bytes); err != nil {
1200+
log.Fatalf("failed to decode embedded document: %v", err)
1201+
}
1202+
```

internal/integration/client_side_encryption_prose_test.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,8 +1381,9 @@ func TestClientSideEncryptionProse(t *testing.T) {
13811381
}
13821382
})
13831383

1384-
// These tests only run when 3 KMS HTTP servers and 1 KMS KMIP server are running. See specification for port numbers and necessary arguments:
1385-
// https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#kms-tls-options-tests
1384+
// These tests only run when 3 KMS HTTP servers and 1 KMS KMIP server are
1385+
// running. See specification for port numbers and necessary arguments:
1386+
// https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#10-kms-tls-tests
13861387
mt.RunOpts("10. kms tls tests", noClientOpts, func(mt *mtest.T) {
13871388
kmsTlsTestcase := os.Getenv("KMS_TLS_TESTCASE")
13881389
if kmsTlsTestcase == "" {
@@ -1436,8 +1437,9 @@ func TestClientSideEncryptionProse(t *testing.T) {
14361437
}
14371438
})
14381439

1439-
// These tests only run when 3 KMS HTTP servers and 1 KMS KMIP server are running. See specification for port numbers and necessary arguments:
1440-
// https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.rst#kms-tls-options-tests
1440+
// These tests only run when 3 KMS HTTP servers and 1 KMS KMIP server are
1441+
// running. See specification for port numbers and necessary arguments:
1442+
// https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/tests/README.md#11-kms-tls-options-tests
14411443
mt.RunOpts("11. kms tls options tests", noClientOpts, func(mt *mtest.T) {
14421444
if os.Getenv("KMS_MOCK_SERVERS_RUNNING") == "" {
14431445
mt.Skipf("Skipping test as KMS_MOCK_SERVERS_RUNNING is not set")

internal/integration/server_selection_prose_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func runsServerSelection(mt *mtest.T, monitor *eventtest.TestPoolMonitor,
105105
}
106106

107107
// TestServerSelectionProse implements the Server Selection prose tests:
108-
// https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection-tests.rst
108+
// https://github.com/mongodb/specifications/blob/master/source/server-selection/server-selection-tests.md
109109
func TestServerSelectionProse(t *testing.T) {
110110
const maxPoolSize = 10
111111
const localThreshold = 30 * time.Second

internal/integration/unified/collection_operation_execution.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,8 @@ func executeDistinct(ctx context.Context, operation *operation) (*operationResul
523523
val := elem.Value()
524524

525525
switch key {
526+
case "hint":
527+
opts.SetHint(val)
526528
case "collation":
527529
collation, err := createCollation(val.Document())
528530
if err != nil {

mongo/collection.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1281,6 +1281,16 @@ func (coll *Collection) Distinct(
12811281
}
12821282
op.Comment(comment)
12831283
}
1284+
if args.Hint != nil {
1285+
if isUnorderedMap(args.Hint) {
1286+
return &DistinctResult{err: ErrMapForOrderedArgument{"hint"}}
1287+
}
1288+
hint, err := marshalValue(args.Hint, coll.bsonOpts, coll.registry)
1289+
if err != nil {
1290+
return &DistinctResult{err: err}
1291+
}
1292+
op.Hint(hint)
1293+
}
12841294
retry := driver.RetryNone
12851295
if coll.client.retryReads {
12861296
retry = driver.RetryOncePerCommand

mongo/options/distinctoptions.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ package options
1313
type DistinctOptions struct {
1414
Collation *Collation
1515
Comment interface{}
16+
Hint interface{}
1617
}
1718

1819
// DistinctOptionsBuilder contains options to configure distinct operations. Each
@@ -60,3 +61,21 @@ func (do *DistinctOptionsBuilder) SetComment(comment interface{}) *DistinctOptio
6061

6162
return do
6263
}
64+
65+
// SetHint specifies the index to use for the operation. This should either be
66+
// the index name as a string or the index specification as a document. This
67+
// option is only valid for MongoDB versions >= 7.1. Previous server versions
68+
// will return an error if an index hint is specified. Distinct returns an error
69+
// if the hint parameter is a multi-key map. The default value is nil, which
70+
// means that no index hint will be sent.
71+
//
72+
// SetHint sets the Hint field.
73+
func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuilder {
74+
do.Opts = append(do.Opts, func(opts *DistinctOptions) error {
75+
opts.Hint = hint
76+
77+
return nil
78+
})
79+
80+
return do
81+
}

testdata/atlas-data-lake-testing/README.rst

Lines changed: 0 additions & 85 deletions
This file was deleted.

testdata/auth/README.rst

Lines changed: 0 additions & 53 deletions
This file was deleted.

testdata/auth/mongodb-aws.rst

Lines changed: 0 additions & 94 deletions
This file was deleted.

0 commit comments

Comments
 (0)