Skip to content

Commit e44b706

Browse files
committed
Correct the SetHint docs and return an error if the hint value is an multi-key map.
1 parent 5c74843 commit e44b706

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

mongo/collection.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,6 +1282,9 @@ func (coll *Collection) Distinct(
12821282
op.Comment(comment)
12831283
}
12841284
if args.Hint != nil {
1285+
if isUnorderedMap(args.Hint) {
1286+
return &DistinctResult{err: ErrMapForOrderedArgument{"hint"}}
1287+
}
12851288
hint, err := marshalValue(args.Hint, coll.bsonOpts, coll.registry)
12861289
if err != nil {
12871290
return &DistinctResult{err: err}

mongo/options/distinctoptions.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,14 @@ func (do *DistinctOptionsBuilder) SetComment(comment interface{}) *DistinctOptio
6262
return do
6363
}
6464

65-
// SetHint sets the value for the Comment field. Specifies a string or document that
66-
// will be included in server logs, profiling logs, and currentOp queries to help trace
67-
// the operation. The default value is nil, which means that no comment will be included
68-
// in the logs.
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.
6973
func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuilder {
7074
do.Opts = append(do.Opts, func(opts *DistinctOptions) error {
7175
opts.Hint = hint

0 commit comments

Comments
 (0)