github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/indexoptions.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 ( 10 "time" 11 ) 12 13 // CreateIndexesOptions represents options that can be used to configure IndexView.CreateOne and IndexView.CreateMany 14 // operations. 15 type CreateIndexesOptions struct { 16 // The number of data-bearing members of a replica set, including the primary, that must complete the index builds 17 // successfully before the primary marks the indexes as ready. This should either be a string or int32 value. The 18 // semantics of the values are as follows: 19 // 20 // 1. String: specifies a tag. All members with that tag must complete the build. 21 // 2. int: the number of members that must complete the build. 22 // 3. "majority": A special value to indicate that more than half the nodes must complete the build. 23 // 4. "votingMembers": A special value to indicate that all voting data-bearing nodes must complete. 24 // 25 // This option is only available on MongoDB versions >= 4.4. A client-side error will be returned if the option 26 // is specified for MongoDB versions <= 4.2. The default value is nil, meaning that the server-side default will be 27 // used. See dochub.mongodb.org/core/index-commit-quorum for more information. 28 CommitQuorum interface{} 29 30 // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there 31 // is no time limit for query execution. 32 // 33 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be used 34 // in its place to control the amount of time that a single operation can run before returning an error. MaxTime 35 // is ignored if Timeout is set on the client. 36 MaxTime *time.Duration 37 } 38 39 // CreateIndexes creates a new CreateIndexesOptions instance. 40 func CreateIndexes() *CreateIndexesOptions { 41 return &CreateIndexesOptions{} 42 } 43 44 // SetMaxTime sets the value for the MaxTime field. 45 // 46 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout 47 // option may be used in its place to control the amount of time that a single operation can 48 // run before returning an error. MaxTime is ignored if Timeout is set on the client. 49 func (c *CreateIndexesOptions) SetMaxTime(d time.Duration) *CreateIndexesOptions { 50 c.MaxTime = &d 51 return c 52 } 53 54 // SetCommitQuorumInt sets the value for the CommitQuorum field as an int32. 55 func (c *CreateIndexesOptions) SetCommitQuorumInt(quorum int32) *CreateIndexesOptions { 56 c.CommitQuorum = quorum 57 return c 58 } 59 60 // SetCommitQuorumString sets the value for the CommitQuorum field as a string. 61 func (c *CreateIndexesOptions) SetCommitQuorumString(quorum string) *CreateIndexesOptions { 62 c.CommitQuorum = quorum 63 return c 64 } 65 66 // SetCommitQuorumMajority sets the value for the CommitQuorum to special "majority" value. 67 func (c *CreateIndexesOptions) SetCommitQuorumMajority() *CreateIndexesOptions { 68 c.CommitQuorum = "majority" 69 return c 70 } 71 72 // SetCommitQuorumVotingMembers sets the value for the CommitQuorum to special "votingMembers" value. 73 func (c *CreateIndexesOptions) SetCommitQuorumVotingMembers() *CreateIndexesOptions { 74 c.CommitQuorum = "votingMembers" 75 return c 76 } 77 78 // MergeCreateIndexesOptions combines the given CreateIndexesOptions into a single CreateIndexesOptions in a last one 79 // wins fashion. 80 // 81 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 82 // single options struct instead. 83 func MergeCreateIndexesOptions(opts ...*CreateIndexesOptions) *CreateIndexesOptions { 84 c := CreateIndexes() 85 for _, opt := range opts { 86 if opt == nil { 87 continue 88 } 89 if opt.MaxTime != nil { 90 c.MaxTime = opt.MaxTime 91 } 92 if opt.CommitQuorum != nil { 93 c.CommitQuorum = opt.CommitQuorum 94 } 95 } 96 97 return c 98 } 99 100 // DropIndexesOptions represents options that can be used to configure IndexView.DropOne and IndexView.DropAll 101 // operations. 102 type DropIndexesOptions struct { 103 // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there 104 // is no time limit for query execution. 105 // 106 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be used 107 // in its place to control the amount of time that a single operation can run before returning an error. MaxTime 108 // is ignored if Timeout is set on the client. 109 MaxTime *time.Duration 110 } 111 112 // DropIndexes creates a new DropIndexesOptions instance. 113 func DropIndexes() *DropIndexesOptions { 114 return &DropIndexesOptions{} 115 } 116 117 // SetMaxTime sets the value for the MaxTime field. 118 // 119 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout 120 // option may be used in its place to control the amount of time that a single operation can 121 // run before returning an error. MaxTime is ignored if Timeout is set on the client. 122 func (d *DropIndexesOptions) SetMaxTime(duration time.Duration) *DropIndexesOptions { 123 d.MaxTime = &duration 124 return d 125 } 126 127 // MergeDropIndexesOptions combines the given DropIndexesOptions into a single DropIndexesOptions in a last-one-wins 128 // fashion. 129 // 130 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 131 // single options struct instead. 132 func MergeDropIndexesOptions(opts ...*DropIndexesOptions) *DropIndexesOptions { 133 c := DropIndexes() 134 for _, opt := range opts { 135 if opt == nil { 136 continue 137 } 138 if opt.MaxTime != nil { 139 c.MaxTime = opt.MaxTime 140 } 141 } 142 143 return c 144 } 145 146 // ListIndexesOptions represents options that can be used to configure an IndexView.List operation. 147 type ListIndexesOptions struct { 148 // The maximum number of documents to be included in each batch returned by the server. 149 BatchSize *int32 150 151 // The maximum amount of time that the query can run on the server. The default value is nil, meaning that there 152 // is no time limit for query execution. 153 // 154 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be used 155 // in its place to control the amount of time that a single operation can run before returning an error. MaxTime 156 // is ignored if Timeout is set on the client. 157 MaxTime *time.Duration 158 } 159 160 // ListIndexes creates a new ListIndexesOptions instance. 161 func ListIndexes() *ListIndexesOptions { 162 return &ListIndexesOptions{} 163 } 164 165 // SetBatchSize sets the value for the BatchSize field. 166 func (l *ListIndexesOptions) SetBatchSize(i int32) *ListIndexesOptions { 167 l.BatchSize = &i 168 return l 169 } 170 171 // SetMaxTime sets the value for the MaxTime field. 172 // 173 // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout 174 // option may be used in its place to control the amount of time that a single operation can 175 // run before returning an error. MaxTime is ignored if Timeout is set on the client. 176 func (l *ListIndexesOptions) SetMaxTime(d time.Duration) *ListIndexesOptions { 177 l.MaxTime = &d 178 return l 179 } 180 181 // MergeListIndexesOptions combines the given ListIndexesOptions instances into a single *ListIndexesOptions in a 182 // last-one-wins fashion. 183 // 184 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 185 // single options struct instead. 186 func MergeListIndexesOptions(opts ...*ListIndexesOptions) *ListIndexesOptions { 187 c := ListIndexes() 188 for _, opt := range opts { 189 if opt == nil { 190 continue 191 } 192 if opt.BatchSize != nil { 193 c.BatchSize = opt.BatchSize 194 } 195 if opt.MaxTime != nil { 196 c.MaxTime = opt.MaxTime 197 } 198 } 199 200 return c 201 } 202 203 // IndexOptions represents options that can be used to configure a new index created through the IndexView.CreateOne 204 // or IndexView.CreateMany operations. 205 type IndexOptions struct { 206 // If true, the index will be built in the background on the server and will not block other tasks. The default 207 // value is false. 208 // 209 // Deprecated: This option has been deprecated in MongoDB version 4.2. 210 Background *bool 211 212 // The length of time, in seconds, for documents to remain in the collection. The default value is 0, which means 213 // that documents will remain in the collection until they're explicitly deleted or the collection is dropped. 214 ExpireAfterSeconds *int32 215 216 // The name of the index. The default value is "[field1]_[direction1]_[field2]_[direction2]...". For example, an 217 // index with the specification {name: 1, age: -1} will be named "name_1_age_-1". 218 Name *string 219 220 // If true, the index will only reference documents that contain the fields specified in the index. The default is 221 // false. 222 Sparse *bool 223 224 // Specifies the storage engine to use for the index. The value must be a document in the form 225 // {<storage engine name>: <options>}. The default value is nil, which means that the default storage engine 226 // will be used. This option is only applicable for MongoDB versions >= 3.0 and is ignored for previous server 227 // versions. 228 StorageEngine interface{} 229 230 // If true, the collection will not accept insertion or update of documents where the index key value matches an 231 // existing value in the index. The default is false. 232 Unique *bool 233 234 // The index version number, either 0 or 1. 235 Version *int32 236 237 // The language that determines the list of stop words and the rules for the stemmer and tokenizer. This option 238 // is only applicable for text indexes and is ignored for other index types. The default value is "english". 239 DefaultLanguage *string 240 241 // The name of the field in the collection's documents that contains the override language for the document. This 242 // option is only applicable for text indexes and is ignored for other index types. The default value is the value 243 // of the DefaultLanguage option. 244 LanguageOverride *string 245 246 // The index version number for a text index. See https://www.mongodb.com/docs/manual/core/index-text/#text-versions for 247 // information about different version numbers. 248 TextVersion *int32 249 250 // A document that contains field and weight pairs. The weight is an integer ranging from 1 to 99,999, inclusive, 251 // indicating the significance of the field relative to the other indexed fields in terms of the score. This option 252 // is only applicable for text indexes and is ignored for other index types. The default value is nil, which means 253 // that every field will have a weight of 1. 254 Weights interface{} 255 256 // The index version number for a 2D sphere index. See https://www.mongodb.com/docs/manual/core/2dsphere/#dsphere-v2 for 257 // information about different version numbers. 258 SphereVersion *int32 259 260 // The precision of the stored geohash value of the location data. This option only applies to 2D indexes and is 261 // ignored for other index types. The value must be between 1 and 32, inclusive. The default value is 26. 262 Bits *int32 263 264 // The upper inclusive boundary for longitude and latitude values. This option is only applicable to 2D indexes and 265 // is ignored for other index types. The default value is 180.0. 266 Max *float64 267 268 // The lower inclusive boundary for longitude and latitude values. This option is only applicable to 2D indexes and 269 // is ignored for other index types. The default value is -180.0. 270 Min *float64 271 272 // The number of units within which to group location values. Location values that are within BucketSize units of 273 // each other will be grouped in the same bucket. This option is only applicable to geoHaystack indexes and is 274 // ignored for other index types. The value must be greater than 0. 275 BucketSize *int32 276 277 // A document that defines which collection documents the index should reference. This option is only valid for 278 // MongoDB versions >= 3.2 and is ignored for previous server versions. 279 PartialFilterExpression interface{} 280 281 // The collation to use for string comparisons for the index. This option is only valid for MongoDB versions >= 3.4. 282 // For previous server versions, the driver will return an error if this option is used. 283 Collation *Collation 284 285 // A document that defines the wildcard projection for the index. 286 WildcardProjection interface{} 287 288 // If true, the index will exist on the target collection but will not be used by the query planner when executing 289 // operations. This option is only valid for MongoDB versions >= 4.4. The default value is false. 290 Hidden *bool 291 } 292 293 // Index creates a new IndexOptions instance. 294 func Index() *IndexOptions { 295 return &IndexOptions{} 296 } 297 298 // SetBackground sets value for the Background field. 299 // 300 // Deprecated: This option has been deprecated in MongoDB version 4.2. 301 func (i *IndexOptions) SetBackground(background bool) *IndexOptions { 302 i.Background = &background 303 return i 304 } 305 306 // SetExpireAfterSeconds sets value for the ExpireAfterSeconds field. 307 func (i *IndexOptions) SetExpireAfterSeconds(seconds int32) *IndexOptions { 308 i.ExpireAfterSeconds = &seconds 309 return i 310 } 311 312 // SetName sets the value for the Name field. 313 func (i *IndexOptions) SetName(name string) *IndexOptions { 314 i.Name = &name 315 return i 316 } 317 318 // SetSparse sets the value of the Sparse field. 319 func (i *IndexOptions) SetSparse(sparse bool) *IndexOptions { 320 i.Sparse = &sparse 321 return i 322 } 323 324 // SetStorageEngine sets the value for the StorageEngine field. 325 func (i *IndexOptions) SetStorageEngine(engine interface{}) *IndexOptions { 326 i.StorageEngine = engine 327 return i 328 } 329 330 // SetUnique sets the value for the Unique field. 331 func (i *IndexOptions) SetUnique(unique bool) *IndexOptions { 332 i.Unique = &unique 333 return i 334 } 335 336 // SetVersion sets the value for the Version field. 337 func (i *IndexOptions) SetVersion(version int32) *IndexOptions { 338 i.Version = &version 339 return i 340 } 341 342 // SetDefaultLanguage sets the value for the DefaultLanguage field. 343 func (i *IndexOptions) SetDefaultLanguage(language string) *IndexOptions { 344 i.DefaultLanguage = &language 345 return i 346 } 347 348 // SetLanguageOverride sets the value of the LanguageOverride field. 349 func (i *IndexOptions) SetLanguageOverride(override string) *IndexOptions { 350 i.LanguageOverride = &override 351 return i 352 } 353 354 // SetTextVersion sets the value for the TextVersion field. 355 func (i *IndexOptions) SetTextVersion(version int32) *IndexOptions { 356 i.TextVersion = &version 357 return i 358 } 359 360 // SetWeights sets the value for the Weights field. 361 func (i *IndexOptions) SetWeights(weights interface{}) *IndexOptions { 362 i.Weights = weights 363 return i 364 } 365 366 // SetSphereVersion sets the value for the SphereVersion field. 367 func (i *IndexOptions) SetSphereVersion(version int32) *IndexOptions { 368 i.SphereVersion = &version 369 return i 370 } 371 372 // SetBits sets the value for the Bits field. 373 func (i *IndexOptions) SetBits(bits int32) *IndexOptions { 374 i.Bits = &bits 375 return i 376 } 377 378 // SetMax sets the value for the Max field. 379 func (i *IndexOptions) SetMax(max float64) *IndexOptions { 380 i.Max = &max 381 return i 382 } 383 384 // SetMin sets the value for the Min field. 385 func (i *IndexOptions) SetMin(min float64) *IndexOptions { 386 i.Min = &min 387 return i 388 } 389 390 // SetBucketSize sets the value for the BucketSize field 391 func (i *IndexOptions) SetBucketSize(bucketSize int32) *IndexOptions { 392 i.BucketSize = &bucketSize 393 return i 394 } 395 396 // SetPartialFilterExpression sets the value for the PartialFilterExpression field. 397 func (i *IndexOptions) SetPartialFilterExpression(expression interface{}) *IndexOptions { 398 i.PartialFilterExpression = expression 399 return i 400 } 401 402 // SetCollation sets the value for the Collation field. 403 func (i *IndexOptions) SetCollation(collation *Collation) *IndexOptions { 404 i.Collation = collation 405 return i 406 } 407 408 // SetWildcardProjection sets the value for the WildcardProjection field. 409 func (i *IndexOptions) SetWildcardProjection(wildcardProjection interface{}) *IndexOptions { 410 i.WildcardProjection = wildcardProjection 411 return i 412 } 413 414 // SetHidden sets the value for the Hidden field. 415 func (i *IndexOptions) SetHidden(hidden bool) *IndexOptions { 416 i.Hidden = &hidden 417 return i 418 } 419 420 // MergeIndexOptions combines the given IndexOptions into a single IndexOptions in a last-one-wins fashion. 421 // 422 // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a 423 // single options struct instead. 424 func MergeIndexOptions(opts ...*IndexOptions) *IndexOptions { 425 i := Index() 426 427 for _, opt := range opts { 428 if opt == nil { 429 continue 430 } 431 if opt.Background != nil { 432 i.Background = opt.Background 433 } 434 if opt.ExpireAfterSeconds != nil { 435 i.ExpireAfterSeconds = opt.ExpireAfterSeconds 436 } 437 if opt.Name != nil { 438 i.Name = opt.Name 439 } 440 if opt.Sparse != nil { 441 i.Sparse = opt.Sparse 442 } 443 if opt.StorageEngine != nil { 444 i.StorageEngine = opt.StorageEngine 445 } 446 if opt.Unique != nil { 447 i.Unique = opt.Unique 448 } 449 if opt.Version != nil { 450 i.Version = opt.Version 451 } 452 if opt.DefaultLanguage != nil { 453 i.DefaultLanguage = opt.DefaultLanguage 454 } 455 if opt.LanguageOverride != nil { 456 i.LanguageOverride = opt.LanguageOverride 457 } 458 if opt.TextVersion != nil { 459 i.TextVersion = opt.TextVersion 460 } 461 if opt.Weights != nil { 462 i.Weights = opt.Weights 463 } 464 if opt.SphereVersion != nil { 465 i.SphereVersion = opt.SphereVersion 466 } 467 if opt.Bits != nil { 468 i.Bits = opt.Bits 469 } 470 if opt.Max != nil { 471 i.Max = opt.Max 472 } 473 if opt.Min != nil { 474 i.Min = opt.Min 475 } 476 if opt.BucketSize != nil { 477 i.BucketSize = opt.BucketSize 478 } 479 if opt.PartialFilterExpression != nil { 480 i.PartialFilterExpression = opt.PartialFilterExpression 481 } 482 if opt.Collation != nil { 483 i.Collation = opt.Collation 484 } 485 if opt.WildcardProjection != nil { 486 i.WildcardProjection = opt.WildcardProjection 487 } 488 if opt.Hidden != nil { 489 i.Hidden = opt.Hidden 490 } 491 } 492 493 return i 494 }