github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/countoptions.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 // CountOptions represents options that can be used to configure a CountDocuments operation. 12 type CountOptions 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 // TODO(GODRIVER-2386): CountOptions executor uses aggregation under the hood, which means this type has to be 19 // TODO a string for now. This can be replaced with `Comment interface{}` once 2386 is implemented. 20 21 // A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace 22 // the operation. The default is nil, which means that no comment will be included in the logs. 23 Comment *string 24 25 // The index to use for the aggregation. This should either be the index name as a string or the index specification 26 // as a document. The driver will return an error if the hint parameter is a multi-key map. The default value is nil, 27 // which means that no hint will be sent. 28 Hint interface{} 29 30 // The maximum number of documents to count. The default value is 0, which means that there is no limit and all 31 // documents matching the filter will be counted. 32 Limit *int64 33 34 // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there is 35 // no time limit for query execution. 36 // 37 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be used in 38 // its place to control the amount of time that a single operation can run before returning an error. MaxTime is 39 // ignored if Timeout is set on the client. 40 MaxTime *time.Duration 41 42 // The number of documents to skip before counting. The default value is 0. 43 Skip *int64 44 } 45 46 // Count creates a new CountOptions instance. 47 func Count() *CountOptions { 48 return &CountOptions{} 49 } 50 51 // SetCollation sets the value for the Collation field. 52 func (co *CountOptions) SetCollation(c *Collation) *CountOptions { 53 co.Collation = c 54 return co 55 } 56 57 // SetComment sets the value for the Comment field. 58 func (co *CountOptions) SetComment(c string) *CountOptions { 59 co.Comment = &c 60 return co 61 } 62 63 // SetHint sets the value for the Hint field. 64 func (co *CountOptions) SetHint(h interface{}) *CountOptions { 65 co.Hint = h 66 return co 67 } 68 69 // SetLimit sets the value for the Limit field. 70 func (co *CountOptions) SetLimit(i int64) *CountOptions { 71 co.Limit = &i 72 return co 73 } 74 75 // SetMaxTime sets the value for the MaxTime field. 76 // 77 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout 78 // option may be used in its place to control the amount of time that a single operation can 79 // run before returning an error. MaxTime is ignored if Timeout is set on the client. 80 func (co *CountOptions) SetMaxTime(d time.Duration) *CountOptions { 81 co.MaxTime = &d 82 return co 83 } 84 85 // SetSkip sets the value for the Skip field. 86 func (co *CountOptions) SetSkip(i int64) *CountOptions { 87 co.Skip = &i 88 return co 89 } 90 91 // MergeCountOptions combines the given CountOptions instances into a single CountOptions in a last-one-wins fashion. 92 // 93 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 94 // single options struct instead. 95 func MergeCountOptions(opts ...*CountOptions) *CountOptions { 96 countOpts := Count() 97 for _, co := range opts { 98 if co == nil { 99 continue 100 } 101 if co.Collation != nil { 102 countOpts.Collation = co.Collation 103 } 104 if co.Comment != nil { 105 countOpts.Comment = co.Comment 106 } 107 if co.Hint != nil { 108 countOpts.Hint = co.Hint 109 } 110 if co.Limit != nil { 111 countOpts.Limit = co.Limit 112 } 113 if co.MaxTime != nil { 114 countOpts.MaxTime = co.MaxTime 115 } 116 if co.Skip != nil { 117 countOpts.Skip = co.Skip 118 } 119 } 120 121 return countOpts 122 }