github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/distinctoptions.go (about) 1 // Copyright (C) MongoDB, Inc. 2017-present. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 6 7 package options 8 9 import "time" 10 11 // DistinctOptions represents options that can be used to configure a Distinct operation. 12 type DistinctOptions struct { 13 // Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB 14 // versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The 15 // default value is nil, which means the default collation of the collection will be used. 16 Collation *Collation 17 18 // A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace 19 // the operation. The default value is nil, which means that no comment will be included in the logs. 20 Comment interface{} 21 22 // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there 23 // is no time limit for query execution. 24 // 25 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be 26 // used in its place to control the amount of time that a single operation can run before returning an error. 27 // MaxTime is ignored if Timeout is set on the client. 28 MaxTime *time.Duration 29 } 30 31 // Distinct creates a new DistinctOptions instance. 32 func Distinct() *DistinctOptions { 33 return &DistinctOptions{} 34 } 35 36 // SetCollation sets the value for the Collation field. 37 func (do *DistinctOptions) SetCollation(c *Collation) *DistinctOptions { 38 do.Collation = c 39 return do 40 } 41 42 // SetComment sets the value for the Comment field. 43 func (do *DistinctOptions) SetComment(comment interface{}) *DistinctOptions { 44 do.Comment = comment 45 return do 46 } 47 48 // SetMaxTime sets the value for the MaxTime field. 49 // 50 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout 51 // option may be used in its place to control the amount of time that a single operation can 52 // run before returning an error. MaxTime is ignored if Timeout is set on the client. 53 func (do *DistinctOptions) SetMaxTime(d time.Duration) *DistinctOptions { 54 do.MaxTime = &d 55 return do 56 } 57 58 // MergeDistinctOptions combines the given DistinctOptions instances into a single DistinctOptions in a last-one-wins 59 // fashion. 60 // 61 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 62 // single options struct instead. 63 func MergeDistinctOptions(opts ...*DistinctOptions) *DistinctOptions { 64 distinctOpts := Distinct() 65 for _, do := range opts { 66 if do == nil { 67 continue 68 } 69 if do.Collation != nil { 70 distinctOpts.Collation = do.Collation 71 } 72 if do.Comment != nil { 73 distinctOpts.Comment = do.Comment 74 } 75 if do.MaxTime != nil { 76 distinctOpts.MaxTime = do.MaxTime 77 } 78 } 79 80 return distinctOpts 81 }