Skip to content

Commit

Permalink
Correct the SetHint docs and return an error if the hint value is an …
Browse files Browse the repository at this point in the history
…multi-key map.
  • Loading branch information
matthewdale committed Nov 13, 2024
1 parent 5c74843 commit e44b706
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions mongo/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,9 @@ func (coll *Collection) Distinct(
op.Comment(comment)
}
if args.Hint != nil {
if isUnorderedMap(args.Hint) {
return &DistinctResult{err: ErrMapForOrderedArgument{"hint"}}
}
hint, err := marshalValue(args.Hint, coll.bsonOpts, coll.registry)
if err != nil {
return &DistinctResult{err: err}
Expand Down
12 changes: 8 additions & 4 deletions mongo/options/distinctoptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,14 @@ func (do *DistinctOptionsBuilder) SetComment(comment interface{}) *DistinctOptio
return do
}

// SetHint sets the value for the Comment field. Specifies a string or document that
// will be included in server logs, profiling logs, and currentOp queries to help trace
// the operation. The default value is nil, which means that no comment will be included
// in the logs.
// SetHint specifies the index to use for the operation. This should either be
// the index name as a string or the index specification as a document. This
// option is only valid for MongoDB versions >= 7.1. Previous server versions
// will return an error if an index hint is specified. Distinct returns an error
// if the hint parameter is a multi-key map. The default value is nil, which
// means that no index hint will be sent.
//
// SetHint sets the Hint field.
func (do *DistinctOptionsBuilder) SetHint(hint interface{}) *DistinctOptionsBuilder {
do.Opts = append(do.Opts, func(opts *DistinctOptions) error {
opts.Hint = hint
Expand Down

0 comments on commit e44b706

Please sign in to comment.