1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956
|
// Copyright (C) MongoDB, Inc. 2017-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package options
import (
"time"
)
// FindOptions represents options that can be used to configure a Find operation.
type FindOptions struct {
// If true, the server can write temporary data to disk while executing the find operation. This option is only
// valid for MongoDB versions >= 4.4. Server versions >= 3.2 will report an error if this option is specified. For
// server versions < 3.2, the driver will return a client-side error if this option is specified. The default value
// is false.
AllowDiskUse *bool
// If true, an operation on a sharded cluster can return partial results if some shards are down rather than
// returning an error. The default value is false.
AllowPartialResults *bool
// The maximum number of documents to be included in each batch returned by the server.
BatchSize *int32
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the default collation of the collection will be used.
Collation *Collation
// A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
// The default is the empty string, which means that no comment will be included in the logs.
Comment *string
// Specifies the type of cursor that should be created for the operation. The default is NonTailable, which means
// that the cursor will be closed by the server when the last batch of documents is retrieved.
CursorType *CursorType
// The index to use for the operation. This should either be the index name as a string or the index specification
// as a document. The driver will return an error if the hint parameter is a multi-key map. The default value is nil,
// which means that no hint will be sent.
Hint interface{}
// The maximum number of documents to return. The default value is 0, which means that all documents matching the
// filter will be returned. A negative limit specifies that the resulting documents should be returned in a single
// batch. The default value is 0.
Limit *int64
// A document specifying the exclusive upper bound for a specific index. The default value is nil, which means that
// there is no maximum value.
Max interface{}
// The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
// This option is only valid for tailable await cursors (see the CursorType option for more information) and
// MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored.
MaxAwaitTime *time.Duration
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
// is no time limit for query execution.
MaxTime *time.Duration
// A document specifying the inclusive lower bound for a specific index. The default value is 0, which means that
// there is no minimum value.
Min interface{}
// If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
// is false.
NoCursorTimeout *bool
// This option is for internal replication use only and should not be set.
//
// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is
// set.
OplogReplay *bool
// A document describing which fields will be included in the documents returned by the operation. The default value
// is nil, which means all fields will be included.
Projection interface{}
// If true, the documents returned by the operation will only contain fields corresponding to the index used. The
// default value is false.
ReturnKey *bool
// If true, a $recordId field with a record identifier will be included in the documents returned by the operation.
// The default value is false.
ShowRecordID *bool
// The number of documents to skip before adding documents to the result. The default value is 0.
Skip *int64
// If true, the cursor will not return a document more than once because of an intervening write operation. The
// default value is false.
//
// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
Snapshot *bool
// A document specifying the order in which documents should be returned. The driver will return an error if the
// sort parameter is a multi-key map.
Sort interface{}
}
// Find creates a new FindOptions instance.
func Find() *FindOptions {
return &FindOptions{}
}
// SetAllowDiskUse sets the value for the AllowDiskUse field.
func (f *FindOptions) SetAllowDiskUse(b bool) *FindOptions {
f.AllowDiskUse = &b
return f
}
// SetAllowPartialResults sets the value for the AllowPartialResults field.
func (f *FindOptions) SetAllowPartialResults(b bool) *FindOptions {
f.AllowPartialResults = &b
return f
}
// SetBatchSize sets the value for the BatchSize field.
func (f *FindOptions) SetBatchSize(i int32) *FindOptions {
f.BatchSize = &i
return f
}
// SetCollation sets the value for the Collation field.
func (f *FindOptions) SetCollation(collation *Collation) *FindOptions {
f.Collation = collation
return f
}
// SetComment sets the value for the Comment field.
func (f *FindOptions) SetComment(comment string) *FindOptions {
f.Comment = &comment
return f
}
// SetCursorType sets the value for the CursorType field.
func (f *FindOptions) SetCursorType(ct CursorType) *FindOptions {
f.CursorType = &ct
return f
}
// SetHint sets the value for the Hint field.
func (f *FindOptions) SetHint(hint interface{}) *FindOptions {
f.Hint = hint
return f
}
// SetLimit sets the value for the Limit field.
func (f *FindOptions) SetLimit(i int64) *FindOptions {
f.Limit = &i
return f
}
// SetMax sets the value for the Max field.
func (f *FindOptions) SetMax(max interface{}) *FindOptions {
f.Max = max
return f
}
// SetMaxAwaitTime sets the value for the MaxAwaitTime field.
func (f *FindOptions) SetMaxAwaitTime(d time.Duration) *FindOptions {
f.MaxAwaitTime = &d
return f
}
// SetMaxTime specifies the max time to allow the query to run.
func (f *FindOptions) SetMaxTime(d time.Duration) *FindOptions {
f.MaxTime = &d
return f
}
// SetMin sets the value for the Min field.
func (f *FindOptions) SetMin(min interface{}) *FindOptions {
f.Min = min
return f
}
// SetNoCursorTimeout sets the value for the NoCursorTimeout field.
func (f *FindOptions) SetNoCursorTimeout(b bool) *FindOptions {
f.NoCursorTimeout = &b
return f
}
// SetOplogReplay sets the value for the OplogReplay field.
//
// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is set.
func (f *FindOptions) SetOplogReplay(b bool) *FindOptions {
f.OplogReplay = &b
return f
}
// SetProjection sets the value for the Projection field.
func (f *FindOptions) SetProjection(projection interface{}) *FindOptions {
f.Projection = projection
return f
}
// SetReturnKey sets the value for the ReturnKey field.
func (f *FindOptions) SetReturnKey(b bool) *FindOptions {
f.ReturnKey = &b
return f
}
// SetShowRecordID sets the value for the ShowRecordID field.
func (f *FindOptions) SetShowRecordID(b bool) *FindOptions {
f.ShowRecordID = &b
return f
}
// SetSkip sets the value for the Skip field.
func (f *FindOptions) SetSkip(i int64) *FindOptions {
f.Skip = &i
return f
}
// SetSnapshot sets the value for the Snapshot field.
//
// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
func (f *FindOptions) SetSnapshot(b bool) *FindOptions {
f.Snapshot = &b
return f
}
// SetSort sets the value for the Sort field.
func (f *FindOptions) SetSort(sort interface{}) *FindOptions {
f.Sort = sort
return f
}
// MergeFindOptions combines the given FindOptions instances into a single FindOptions in a last-one-wins fashion.
func MergeFindOptions(opts ...*FindOptions) *FindOptions {
fo := Find()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.AllowDiskUse != nil {
fo.AllowDiskUse = opt.AllowDiskUse
}
if opt.AllowPartialResults != nil {
fo.AllowPartialResults = opt.AllowPartialResults
}
if opt.BatchSize != nil {
fo.BatchSize = opt.BatchSize
}
if opt.Collation != nil {
fo.Collation = opt.Collation
}
if opt.Comment != nil {
fo.Comment = opt.Comment
}
if opt.CursorType != nil {
fo.CursorType = opt.CursorType
}
if opt.Hint != nil {
fo.Hint = opt.Hint
}
if opt.Limit != nil {
fo.Limit = opt.Limit
}
if opt.Max != nil {
fo.Max = opt.Max
}
if opt.MaxAwaitTime != nil {
fo.MaxAwaitTime = opt.MaxAwaitTime
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Min != nil {
fo.Min = opt.Min
}
if opt.NoCursorTimeout != nil {
fo.NoCursorTimeout = opt.NoCursorTimeout
}
if opt.OplogReplay != nil {
fo.OplogReplay = opt.OplogReplay
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
if opt.ReturnKey != nil {
fo.ReturnKey = opt.ReturnKey
}
if opt.ShowRecordID != nil {
fo.ShowRecordID = opt.ShowRecordID
}
if opt.Skip != nil {
fo.Skip = opt.Skip
}
if opt.Snapshot != nil {
fo.Snapshot = opt.Snapshot
}
if opt.Sort != nil {
fo.Sort = opt.Sort
}
}
return fo
}
// FindOneOptions represents options that can be used to configure a FindOne operation.
type FindOneOptions struct {
// If true, an operation on a sharded cluster can return partial results if some shards are down rather than
// returning an error. The default value is false.
AllowPartialResults *bool
// The maximum number of documents to be included in each batch returned by the server.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
BatchSize *int32
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the default collation of the collection will be used.
Collation *Collation
// A string that will be included in server logs, profiling logs, and currentOp queries to help trace the operation.
// The default is the empty string, which means that no comment will be included in the logs.
Comment *string
// Specifies the type of cursor that should be created for the operation. The default is NonTailable, which means
// that the cursor will be closed by the server when the last batch of documents is retrieved.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
CursorType *CursorType
// The index to use for the aggregation. This should either be the index name as a string or the index specification
// as a document. The driver will return an error if the hint parameter is a multi-key map. The default value is nil,
// which means that no hint will be sent.
Hint interface{}
// A document specifying the exclusive upper bound for a specific index. The default value is nil, which means that
// there is no maximum value.
Max interface{}
// The maximum amount of time that the server should wait for new documents to satisfy a tailable cursor query.
// This option is only valid for tailable await cursors (see the CursorType option for more information) and
// MongoDB versions >= 3.2. For other cursor types or previous server versions, this option is ignored.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
MaxAwaitTime *time.Duration
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
// is no time limit for query execution.
MaxTime *time.Duration
// A document specifying the inclusive lower bound for a specific index. The default value is 0, which means that
// there is no minimum value.
Min interface{}
// If true, the cursor created by the operation will not timeout after a period of inactivity. The default value
// is false.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
NoCursorTimeout *bool
// This option is for internal replication use only and should not be set.
//
// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is
// set.
OplogReplay *bool
// A document describing which fields will be included in the document returned by the operation. The default value
// is nil, which means all fields will be included.
Projection interface{}
// If true, the document returned by the operation will only contain fields corresponding to the index used. The
// default value is false.
ReturnKey *bool
// If true, a $recordId field with a record identifier will be included in the document returned by the operation.
// The default value is false.
ShowRecordID *bool
// The number of documents to skip before selecting the document to be returned. The default value is 0.
Skip *int64
// If true, the cursor will not return a document more than once because of an intervening write operation. The
// default value is false.
//
// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
Snapshot *bool
// A document specifying the sort order to apply to the query. The first document in the sorted order will be
// returned. The driver will return an error if the sort parameter is a multi-key map.
Sort interface{}
}
// FindOne creates a new FindOneOptions instance.
func FindOne() *FindOneOptions {
return &FindOneOptions{}
}
// SetAllowPartialResults sets the value for the AllowPartialResults field.
func (f *FindOneOptions) SetAllowPartialResults(b bool) *FindOneOptions {
f.AllowPartialResults = &b
return f
}
// SetBatchSize sets the value for the BatchSize field.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
func (f *FindOneOptions) SetBatchSize(i int32) *FindOneOptions {
f.BatchSize = &i
return f
}
// SetCollation sets the value for the Collation field.
func (f *FindOneOptions) SetCollation(collation *Collation) *FindOneOptions {
f.Collation = collation
return f
}
// SetComment sets the value for the Comment field.
func (f *FindOneOptions) SetComment(comment string) *FindOneOptions {
f.Comment = &comment
return f
}
// SetCursorType sets the value for the CursorType field.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
func (f *FindOneOptions) SetCursorType(ct CursorType) *FindOneOptions {
f.CursorType = &ct
return f
}
// SetHint sets the value for the Hint field.
func (f *FindOneOptions) SetHint(hint interface{}) *FindOneOptions {
f.Hint = hint
return f
}
// SetMax sets the value for the Max field.
func (f *FindOneOptions) SetMax(max interface{}) *FindOneOptions {
f.Max = max
return f
}
// SetMaxAwaitTime sets the value for the MaxAwaitTime field.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
func (f *FindOneOptions) SetMaxAwaitTime(d time.Duration) *FindOneOptions {
f.MaxAwaitTime = &d
return f
}
// SetMaxTime sets the value for the MaxTime field.
func (f *FindOneOptions) SetMaxTime(d time.Duration) *FindOneOptions {
f.MaxTime = &d
return f
}
// SetMin sets the value for the Min field.
func (f *FindOneOptions) SetMin(min interface{}) *FindOneOptions {
f.Min = min
return f
}
// SetNoCursorTimeout sets the value for the NoCursorTimeout field.
//
// Deprecated: This option is not valid for a findOne operation, as no cursor is actually created.
func (f *FindOneOptions) SetNoCursorTimeout(b bool) *FindOneOptions {
f.NoCursorTimeout = &b
return f
}
// SetOplogReplay sets the value for the OplogReplay field.
//
// Deprecated: This option has been deprecated in MongoDB version 4.4 and will be ignored by the server if it is
// set.
func (f *FindOneOptions) SetOplogReplay(b bool) *FindOneOptions {
f.OplogReplay = &b
return f
}
// SetProjection sets the value for the Projection field.
func (f *FindOneOptions) SetProjection(projection interface{}) *FindOneOptions {
f.Projection = projection
return f
}
// SetReturnKey sets the value for the ReturnKey field.
func (f *FindOneOptions) SetReturnKey(b bool) *FindOneOptions {
f.ReturnKey = &b
return f
}
// SetShowRecordID sets the value for the ShowRecordID field.
func (f *FindOneOptions) SetShowRecordID(b bool) *FindOneOptions {
f.ShowRecordID = &b
return f
}
// SetSkip sets the value for the Skip field.
func (f *FindOneOptions) SetSkip(i int64) *FindOneOptions {
f.Skip = &i
return f
}
// SetSnapshot sets the value for the Snapshot field.
//
// Deprecated: This option has been deprecated in MongoDB version 3.6 and removed in MongoDB version 4.0.
func (f *FindOneOptions) SetSnapshot(b bool) *FindOneOptions {
f.Snapshot = &b
return f
}
// SetSort sets the value for the Sort field.
func (f *FindOneOptions) SetSort(sort interface{}) *FindOneOptions {
f.Sort = sort
return f
}
// MergeFindOneOptions combines the given FindOneOptions instances into a single FindOneOptions in a last-one-wins
// fashion.
func MergeFindOneOptions(opts ...*FindOneOptions) *FindOneOptions {
fo := FindOne()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.AllowPartialResults != nil {
fo.AllowPartialResults = opt.AllowPartialResults
}
if opt.BatchSize != nil {
fo.BatchSize = opt.BatchSize
}
if opt.Collation != nil {
fo.Collation = opt.Collation
}
if opt.Comment != nil {
fo.Comment = opt.Comment
}
if opt.CursorType != nil {
fo.CursorType = opt.CursorType
}
if opt.Hint != nil {
fo.Hint = opt.Hint
}
if opt.Max != nil {
fo.Max = opt.Max
}
if opt.MaxAwaitTime != nil {
fo.MaxAwaitTime = opt.MaxAwaitTime
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Min != nil {
fo.Min = opt.Min
}
if opt.NoCursorTimeout != nil {
fo.NoCursorTimeout = opt.NoCursorTimeout
}
if opt.OplogReplay != nil {
fo.OplogReplay = opt.OplogReplay
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
if opt.ReturnKey != nil {
fo.ReturnKey = opt.ReturnKey
}
if opt.ShowRecordID != nil {
fo.ShowRecordID = opt.ShowRecordID
}
if opt.Skip != nil {
fo.Skip = opt.Skip
}
if opt.Snapshot != nil {
fo.Snapshot = opt.Snapshot
}
if opt.Sort != nil {
fo.Sort = opt.Sort
}
}
return fo
}
// FindOneAndReplaceOptions represents options that can be used to configure a FindOneAndReplace instance.
type FindOneAndReplaceOptions struct {
// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
// false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
// validation.
BypassDocumentValidation *bool
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the default collation of the collection will be used.
Collation *Collation
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
// is no time limit for query execution.
MaxTime *time.Duration
// A document describing which fields will be included in the document returned by the operation. The default value
// is nil, which means all fields will be included.
Projection interface{}
// Specifies whether the original or replaced document should be returned by the operation. The default value is
// Before, which means the original document will be returned from before the replacement is performed.
ReturnDocument *ReturnDocument
// A document specifying which document should be replaced if the filter used by the operation matches multiple
// documents in the collection. If set, the first document in the sorted order will be replaced. The driver will
// return an error if the sort parameter is a multi-key map. The default value is nil.
Sort interface{}
// If true, a new document will be inserted if the filter does not match any documents in the collection. The
// default value is false.
Upsert *bool
// 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 >= 4.4. MongoDB version 4.2 will report an error if
// this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
// The driver will return an error if this option is used with during an unacknowledged write operation. The driver
// will return an error if the hint parameter is a multi-key map. The default value is nil, which means that no hint
// will be sent.
Hint interface{}
}
// FindOneAndReplace creates a new FindOneAndReplaceOptions instance.
func FindOneAndReplace() *FindOneAndReplaceOptions {
return &FindOneAndReplaceOptions{}
}
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
func (f *FindOneAndReplaceOptions) SetBypassDocumentValidation(b bool) *FindOneAndReplaceOptions {
f.BypassDocumentValidation = &b
return f
}
// SetCollation sets the value for the Collation field.
func (f *FindOneAndReplaceOptions) SetCollation(collation *Collation) *FindOneAndReplaceOptions {
f.Collation = collation
return f
}
// SetMaxTime sets the value for the MaxTime field.
func (f *FindOneAndReplaceOptions) SetMaxTime(d time.Duration) *FindOneAndReplaceOptions {
f.MaxTime = &d
return f
}
// SetProjection sets the value for the Projection field.
func (f *FindOneAndReplaceOptions) SetProjection(projection interface{}) *FindOneAndReplaceOptions {
f.Projection = projection
return f
}
// SetReturnDocument sets the value for the ReturnDocument field.
func (f *FindOneAndReplaceOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndReplaceOptions {
f.ReturnDocument = &rd
return f
}
// SetSort sets the value for the Sort field.
func (f *FindOneAndReplaceOptions) SetSort(sort interface{}) *FindOneAndReplaceOptions {
f.Sort = sort
return f
}
// SetUpsert sets the value for the Upsert field.
func (f *FindOneAndReplaceOptions) SetUpsert(b bool) *FindOneAndReplaceOptions {
f.Upsert = &b
return f
}
// SetHint sets the value for the Hint field.
func (f *FindOneAndReplaceOptions) SetHint(hint interface{}) *FindOneAndReplaceOptions {
f.Hint = hint
return f
}
// MergeFindOneAndReplaceOptions combines the given FindOneAndReplaceOptions instances into a single
// FindOneAndReplaceOptions in a last-one-wins fashion.
func MergeFindOneAndReplaceOptions(opts ...*FindOneAndReplaceOptions) *FindOneAndReplaceOptions {
fo := FindOneAndReplace()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.BypassDocumentValidation != nil {
fo.BypassDocumentValidation = opt.BypassDocumentValidation
}
if opt.Collation != nil {
fo.Collation = opt.Collation
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
if opt.ReturnDocument != nil {
fo.ReturnDocument = opt.ReturnDocument
}
if opt.Sort != nil {
fo.Sort = opt.Sort
}
if opt.Upsert != nil {
fo.Upsert = opt.Upsert
}
if opt.Hint != nil {
fo.Hint = opt.Hint
}
}
return fo
}
// FindOneAndUpdateOptions represents options that can be used to configure a FindOneAndUpdate options.
type FindOneAndUpdateOptions struct {
// A set of filters specifying to which array elements an update should apply. This option is only valid for MongoDB
// versions >= 3.6. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the update will apply to all array elements.
ArrayFilters *ArrayFilters
// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
// false. See https://docs.mongodb.com/manual/core/schema-validation/ for more information about document
// validation.
BypassDocumentValidation *bool
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the default collation of the collection will be used.
Collation *Collation
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
// is no time limit for query execution.
MaxTime *time.Duration
// A document describing which fields will be included in the document returned by the operation. The default value
// is nil, which means all fields will be included.
Projection interface{}
// Specifies whether the original or replaced document should be returned by the operation. The default value is
// Before, which means the original document will be returned before the replacement is performed.
ReturnDocument *ReturnDocument
// A document specifying which document should be updated if the filter used by the operation matches multiple
// documents in the collection. If set, the first document in the sorted order will be updated. The driver will
// return an error if the sort parameter is a multi-key map. The default value is nil.
Sort interface{}
// If true, a new document will be inserted if the filter does not match any documents in the collection. The
// default value is false.
Upsert *bool
// 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 >= 4.4. MongoDB version 4.2 will report an error if
// this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
// The driver will return an error if this option is used with during an unacknowledged write operation. The driver
// will return an error if the hint parameter is a multi-key map. The default value is nil, which means that no hint
// will be sent.
Hint interface{}
}
// FindOneAndUpdate creates a new FindOneAndUpdateOptions instance.
func FindOneAndUpdate() *FindOneAndUpdateOptions {
return &FindOneAndUpdateOptions{}
}
// SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
func (f *FindOneAndUpdateOptions) SetBypassDocumentValidation(b bool) *FindOneAndUpdateOptions {
f.BypassDocumentValidation = &b
return f
}
// SetArrayFilters sets the value for the ArrayFilters field.
func (f *FindOneAndUpdateOptions) SetArrayFilters(filters ArrayFilters) *FindOneAndUpdateOptions {
f.ArrayFilters = &filters
return f
}
// SetCollation sets the value for the Collation field.
func (f *FindOneAndUpdateOptions) SetCollation(collation *Collation) *FindOneAndUpdateOptions {
f.Collation = collation
return f
}
// SetMaxTime sets the value for the MaxTime field.
func (f *FindOneAndUpdateOptions) SetMaxTime(d time.Duration) *FindOneAndUpdateOptions {
f.MaxTime = &d
return f
}
// SetProjection sets the value for the Projection field.
func (f *FindOneAndUpdateOptions) SetProjection(projection interface{}) *FindOneAndUpdateOptions {
f.Projection = projection
return f
}
// SetReturnDocument sets the value for the ReturnDocument field.
func (f *FindOneAndUpdateOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndUpdateOptions {
f.ReturnDocument = &rd
return f
}
// SetSort sets the value for the Sort field.
func (f *FindOneAndUpdateOptions) SetSort(sort interface{}) *FindOneAndUpdateOptions {
f.Sort = sort
return f
}
// SetUpsert sets the value for the Upsert field.
func (f *FindOneAndUpdateOptions) SetUpsert(b bool) *FindOneAndUpdateOptions {
f.Upsert = &b
return f
}
// SetHint sets the value for the Hint field.
func (f *FindOneAndUpdateOptions) SetHint(hint interface{}) *FindOneAndUpdateOptions {
f.Hint = hint
return f
}
// MergeFindOneAndUpdateOptions combines the given FindOneAndUpdateOptions instances into a single
// FindOneAndUpdateOptions in a last-one-wins fashion.
func MergeFindOneAndUpdateOptions(opts ...*FindOneAndUpdateOptions) *FindOneAndUpdateOptions {
fo := FindOneAndUpdate()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.ArrayFilters != nil {
fo.ArrayFilters = opt.ArrayFilters
}
if opt.BypassDocumentValidation != nil {
fo.BypassDocumentValidation = opt.BypassDocumentValidation
}
if opt.Collation != nil {
fo.Collation = opt.Collation
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
if opt.ReturnDocument != nil {
fo.ReturnDocument = opt.ReturnDocument
}
if opt.Sort != nil {
fo.Sort = opt.Sort
}
if opt.Upsert != nil {
fo.Upsert = opt.Upsert
}
if opt.Hint != nil {
fo.Hint = opt.Hint
}
}
return fo
}
// FindOneAndDeleteOptions represents options that can be used to configure a FindOneAndDelete operation.
type FindOneAndDeleteOptions struct {
// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
// default value is nil, which means the default collation of the collection will be used.
Collation *Collation
// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
// is no time limit for query execution.
MaxTime *time.Duration
// A document describing which fields will be included in the document returned by the operation. The default value
// is nil, which means all fields will be included.
Projection interface{}
// A document specifying which document should be replaced if the filter used by the operation matches multiple
// documents in the collection. If set, the first document in the sorted order will be selected for replacement.
// The driver will return an error if the sort parameter is a multi-key map. The default value is nil.
Sort interface{}
// 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 >= 4.4. MongoDB version 4.2 will report an error if
// this option is specified. For server versions < 4.2, the driver will return an error if this option is specified.
// The driver will return an error if this option is used with during an unacknowledged write operation. The driver
// will return an error if the hint parameter is a multi-key map. The default value is nil, which means that no hint
// will be sent.
Hint interface{}
}
// FindOneAndDelete creates a new FindOneAndDeleteOptions instance.
func FindOneAndDelete() *FindOneAndDeleteOptions {
return &FindOneAndDeleteOptions{}
}
// SetCollation sets the value for the Collation field.
func (f *FindOneAndDeleteOptions) SetCollation(collation *Collation) *FindOneAndDeleteOptions {
f.Collation = collation
return f
}
// SetMaxTime sets the value for the MaxTime field.
func (f *FindOneAndDeleteOptions) SetMaxTime(d time.Duration) *FindOneAndDeleteOptions {
f.MaxTime = &d
return f
}
// SetProjection sets the value for the Projection field.
func (f *FindOneAndDeleteOptions) SetProjection(projection interface{}) *FindOneAndDeleteOptions {
f.Projection = projection
return f
}
// SetSort sets the value for the Sort field.
func (f *FindOneAndDeleteOptions) SetSort(sort interface{}) *FindOneAndDeleteOptions {
f.Sort = sort
return f
}
// SetHint sets the value for the Hint field.
func (f *FindOneAndDeleteOptions) SetHint(hint interface{}) *FindOneAndDeleteOptions {
f.Hint = hint
return f
}
// MergeFindOneAndDeleteOptions combines the given FindOneAndDeleteOptions instances into a single
// FindOneAndDeleteOptions in a last-one-wins fashion.
func MergeFindOneAndDeleteOptions(opts ...*FindOneAndDeleteOptions) *FindOneAndDeleteOptions {
fo := FindOneAndDelete()
for _, opt := range opts {
if opt == nil {
continue
}
if opt.Collation != nil {
fo.Collation = opt.Collation
}
if opt.MaxTime != nil {
fo.MaxTime = opt.MaxTime
}
if opt.Projection != nil {
fo.Projection = opt.Projection
}
if opt.Sort != nil {
fo.Sort = opt.Sort
}
if opt.Hint != nil {
fo.Hint = opt.Hint
}
}
return fo
}
|