forked from mongodb/mongo-go-driver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
findoptions.go
693 lines (615 loc) · 23.1 KB
/
findoptions.go
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
// 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 represent all possible options to the find() function.
type FindOptions struct {
AllowPartialResults *bool // If true, allows partial results to be returned if some shards are down.
BatchSize *int32 // Specifies the number of documents to return in every batch.
Collation *Collation // Specifies a collation to be used
Comment *string // Specifies a string to help trace the operation through the database.
CursorType *CursorType // Specifies the type of cursor to use
Hint interface{} // Specifies the index to use.
Limit *int64 // Sets a limit on the number of results to return.
Max interface{} // Sets an exclusive upper bound for a specific index
MaxAwaitTime *time.Duration // Specifies the maximum amount of time for the server to wait on new documents.
MaxTime *time.Duration // Specifies the maximum amount of time to allow the query to run.
Min interface{} // Specifies the inclusive lower bound for a specific index.
NoCursorTimeout *bool // If true, prevents cursors from timing out after an inactivity period.
OplogReplay *bool // Adds an option for internal use only and should not be set.
Projection interface{} // Limits the fields returned for all documents.
ReturnKey *bool // If true, only returns index keys for all result documents.
ShowRecordID *bool // If true, a $recordId field with the record identifier will be added to the returned documents.
Skip *int64 // Specifies the number of documents to skip before returning
Snapshot *bool // If true, prevents the cursor from returning a document more than once because of an intervening write operation.
Sort interface{} // Specifies the order in which to return results.
}
// Find creates a new FindOptions instance.
func Find() *FindOptions {
return &FindOptions{}
}
// SetAllowPartialResults sets whether partial results can be returned if some shards are down.
// For server versions < 3.2, this defaults to false.
func (f *FindOptions) SetAllowPartialResults(b bool) *FindOptions {
f.AllowPartialResults = &b
return f
}
// SetBatchSize sets the number of documents to return in each batch.
func (f *FindOptions) SetBatchSize(i int32) *FindOptions {
f.BatchSize = &i
return f
}
// SetCollation specifies a Collation to use for the Find operation.
// Valid for server versions >= 3.4
func (f *FindOptions) SetCollation(collation *Collation) *FindOptions {
f.Collation = collation
return f
}
// SetComment specifies a string to help trace the operation through the database.
func (f *FindOptions) SetComment(comment string) *FindOptions {
f.Comment = &comment
return f
}
// SetCursorType specifes the type of cursor to use.
func (f *FindOptions) SetCursorType(ct CursorType) *FindOptions {
f.CursorType = &ct
return f
}
// SetHint specifies the index to use.
func (f *FindOptions) SetHint(hint interface{}) *FindOptions {
f.Hint = hint
return f
}
// SetLimit specifies a limit on the number of results.
// A negative limit implies that only 1 batch should be returned.
func (f *FindOptions) SetLimit(i int64) *FindOptions {
f.Limit = &i
return f
}
// SetMax specifies an exclusive upper bound for a specific index.
func (f *FindOptions) SetMax(max interface{}) *FindOptions {
f.Max = max
return f
}
// SetMaxAwaitTime specifies the max amount of time for the server to wait on new documents.
// If the cursor type is not TailableAwait, this option is ignored.
// For server versions < 3.2, this option is ignored.
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 specifies the inclusive lower bound for a specific index.
func (f *FindOptions) SetMin(min interface{}) *FindOptions {
f.Min = min
return f
}
// SetNoCursorTimeout specifies whether or not cursors should time out after a period of inactivity.
// For server versions < 3.2, this defaults to false.
func (f *FindOptions) SetNoCursorTimeout(b bool) *FindOptions {
f.NoCursorTimeout = &b
return f
}
// SetOplogReplay adds an option for internal use only and should not be set.
// For server versions < 3.2, this defaults to false.
func (f *FindOptions) SetOplogReplay(b bool) *FindOptions {
f.OplogReplay = &b
return f
}
// SetProjection adds an option to limit the fields returned for all documents.
func (f *FindOptions) SetProjection(projection interface{}) *FindOptions {
f.Projection = projection
return f
}
// SetReturnKey adds an option to only return index keys for all result documents.
func (f *FindOptions) SetReturnKey(b bool) *FindOptions {
f.ReturnKey = &b
return f
}
// SetShowRecordID adds an option to determine whether to return the record identifier for each document.
// If true, a $recordId field will be added to each returned document.
func (f *FindOptions) SetShowRecordID(b bool) *FindOptions {
f.ShowRecordID = &b
return f
}
// SetSkip specifies the number of documents to skip before returning.
// For server versions < 3.2, this defaults to 0.
func (f *FindOptions) SetSkip(i int64) *FindOptions {
f.Skip = &i
return f
}
// SetSnapshot prevents the cursor from returning a document more than once because of an intervening write operation.
func (f *FindOptions) SetSnapshot(b bool) *FindOptions {
f.Snapshot = &b
return f
}
// SetSort specifies the order in which to return documents.
func (f *FindOptions) SetSort(sort interface{}) *FindOptions {
f.Sort = sort
return f
}
// MergeFindOptions combines the argued FindOptions 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.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 represent all possible options to the findOne() function.
type FindOneOptions struct {
AllowPartialResults *bool // If true, allows partial results to be returned if some shards are down.
BatchSize *int32 // Specifies the number of documents to return in every batch.
Collation *Collation // Specifies a collation to be used
Comment *string // Specifies a string to help trace the operation through the database.
CursorType *CursorType // Specifies the type of cursor to use
Hint interface{} // Specifies the index to use.
Max interface{} // Sets an exclusive upper bound for a specific index
MaxAwaitTime *time.Duration // Specifies the maximum amount of time for the server to wait on new documents.
MaxTime *time.Duration // Specifies the maximum amount of time to allow the query to run.
Min interface{} // Specifies the inclusive lower bound for a specific index.
NoCursorTimeout *bool // If true, prevents cursors from timing out after an inactivity period.
OplogReplay *bool // Adds an option for internal use only and should not be set.
Projection interface{} // Limits the fields returned for all documents.
ReturnKey *bool // If true, only returns index keys for all result documents.
ShowRecordID *bool // If true, a $recordId field with the record identifier will be added to the returned documents.
Skip *int64 // Specifies the number of documents to skip before returning
Snapshot *bool // If true, prevents the cursor from returning a document more than once because of an intervening write operation.
Sort interface{} // Specifies the order in which to return results.
}
// FindOne creates a new FindOneOptions instance.
func FindOne() *FindOneOptions {
return &FindOneOptions{}
}
// SetAllowPartialResults sets whether partial results can be returned if some shards are down.
func (f *FindOneOptions) SetAllowPartialResults(b bool) *FindOneOptions {
f.AllowPartialResults = &b
return f
}
// SetBatchSize sets the number of documents to return in each batch.
func (f *FindOneOptions) SetBatchSize(i int32) *FindOneOptions {
f.BatchSize = &i
return f
}
// SetCollation specifies a Collation to use for the Find operation.
func (f *FindOneOptions) SetCollation(collation *Collation) *FindOneOptions {
f.Collation = collation
return f
}
// SetComment specifies a string to help trace the operation through the database.
func (f *FindOneOptions) SetComment(comment string) *FindOneOptions {
f.Comment = &comment
return f
}
// SetCursorType specifes the type of cursor to use.
func (f *FindOneOptions) SetCursorType(ct CursorType) *FindOneOptions {
f.CursorType = &ct
return f
}
// SetHint specifies the index to use.
func (f *FindOneOptions) SetHint(hint interface{}) *FindOneOptions {
f.Hint = hint
return f
}
// SetMax specifies an exclusive upper bound for a specific index.
func (f *FindOneOptions) SetMax(max interface{}) *FindOneOptions {
f.Max = max
return f
}
// SetMaxAwaitTime specifies the max amount of time for the server to wait on new documents.
// For server versions < 3.2, this option is ignored.
func (f *FindOneOptions) SetMaxAwaitTime(d time.Duration) *FindOneOptions {
f.MaxAwaitTime = &d
return f
}
// SetMaxTime specifies the max time to allow the query to run.
func (f *FindOneOptions) SetMaxTime(d time.Duration) *FindOneOptions {
f.MaxTime = &d
return f
}
// SetMin specifies the inclusive lower bound for a specific index.
func (f *FindOneOptions) SetMin(min interface{}) *FindOneOptions {
f.Min = min
return f
}
// SetNoCursorTimeout specifies whether or not cursors should time out after a period of inactivity.
func (f *FindOneOptions) SetNoCursorTimeout(b bool) *FindOneOptions {
f.NoCursorTimeout = &b
return f
}
// SetOplogReplay adds an option for internal use only and should not be set.
func (f *FindOneOptions) SetOplogReplay(b bool) *FindOneOptions {
f.OplogReplay = &b
return f
}
// SetProjection adds an option to limit the fields returned for all documents.
func (f *FindOneOptions) SetProjection(projection interface{}) *FindOneOptions {
f.Projection = projection
return f
}
// SetReturnKey adds an option to only return index keys for all result documents.
func (f *FindOneOptions) SetReturnKey(b bool) *FindOneOptions {
f.ReturnKey = &b
return f
}
// SetShowRecordID adds an option to determine whether to return the record identifier for each document.
// If true, a $recordId field will be added to each returned document.
func (f *FindOneOptions) SetShowRecordID(b bool) *FindOneOptions {
f.ShowRecordID = &b
return f
}
// SetSkip specifies the number of documents to skip before returning.
func (f *FindOneOptions) SetSkip(i int64) *FindOneOptions {
f.Skip = &i
return f
}
// SetSnapshot prevents the cursor from returning a document more than once because of an intervening write operation.
func (f *FindOneOptions) SetSnapshot(b bool) *FindOneOptions {
f.Snapshot = &b
return f
}
// SetSort specifies the order in which to return documents.
func (f *FindOneOptions) SetSort(sort interface{}) *FindOneOptions {
f.Sort = sort
return f
}
// MergeFindOneOptions combines the argued FindOneOptions 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 represent all possible options to the findOne() function.
type FindOneAndReplaceOptions struct {
BypassDocumentValidation *bool // If true, allows the write to opt out of document-level validation.
Collation *Collation // Specifies a collation to be used
MaxTime *time.Duration // Specifies the maximum amount of time to allow the query to run.
Projection interface{} // Limits the fields returned for all documents.
ReturnDocument *ReturnDocument // Specifies whether the original or updated document should be returned.
Sort interface{} // Specifies the order in which to return results.
Upsert *bool // If true, creates a a new document if no document matches the query.
}
// FindOneAndReplace creates a new FindOneAndReplaceOptions instance.
func FindOneAndReplace() *FindOneAndReplaceOptions {
return &FindOneAndReplaceOptions{}
}
// SetBypassDocumentValidation specifies whether or not the write should opt out of document-level validation.
// Valid for server versions >= 3.2. For servers < 3.2, this option is ignored.
func (f *FindOneAndReplaceOptions) SetBypassDocumentValidation(b bool) *FindOneAndReplaceOptions {
f.BypassDocumentValidation = &b
return f
}
// SetCollation specifies a Collation to use for the Find operation.
func (f *FindOneAndReplaceOptions) SetCollation(collation *Collation) *FindOneAndReplaceOptions {
f.Collation = collation
return f
}
// SetMaxTime specifies the max time to allow the query to run.
func (f *FindOneAndReplaceOptions) SetMaxTime(d time.Duration) *FindOneAndReplaceOptions {
f.MaxTime = &d
return f
}
// SetProjection adds an option to limit the fields returned for all documents.
func (f *FindOneAndReplaceOptions) SetProjection(projection interface{}) *FindOneAndReplaceOptions {
f.Projection = projection
return f
}
// SetReturnDocument specifies whether the original or updated document should be returned.
// If set to Before, the original document will be returned. If set to After, the updated document
// will be returned.
func (f *FindOneAndReplaceOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndReplaceOptions {
f.ReturnDocument = &rd
return f
}
// SetSort specifies the order in which to return documents.
func (f *FindOneAndReplaceOptions) SetSort(sort interface{}) *FindOneAndReplaceOptions {
f.Sort = sort
return f
}
// SetUpsert specifies if a new document should be created if no document matches the query.
func (f *FindOneAndReplaceOptions) SetUpsert(b bool) *FindOneAndReplaceOptions {
f.Upsert = &b
return f
}
// MergeFindOneAndReplaceOptions combines the argued FindOneAndReplaceOptions 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
}
}
return fo
}
// FindOneAndUpdateOptions represent all possible options to the findOne() function.
type FindOneAndUpdateOptions struct {
ArrayFilters *ArrayFilters // A set of filters specifying to which array elements an update should apply.
BypassDocumentValidation *bool // If true, allows the write to opt out of document-level validation.
Collation *Collation // Specifies a collation to be used
MaxTime *time.Duration // Specifies the maximum amount of time to allow the query to run.
Projection interface{} // Limits the fields returned for all documents.
ReturnDocument *ReturnDocument // Specifies whether the original or updated document should be returned.
Sort interface{} // Specifies the order in which to return results.
Upsert *bool // If true, creates a a new document if no document matches the query.
}
// FindOneAndUpdate creates a new FindOneAndUpdateOptions instance.
func FindOneAndUpdate() *FindOneAndUpdateOptions {
return &FindOneAndUpdateOptions{}
}
// SetBypassDocumentValidation sets filters that specify to which array elements an update should apply.
func (f *FindOneAndUpdateOptions) SetBypassDocumentValidation(b bool) *FindOneAndUpdateOptions {
f.BypassDocumentValidation = &b
return f
}
// SetArrayFilters specifies a set of filters, which
func (f *FindOneAndUpdateOptions) SetArrayFilters(filters ArrayFilters) *FindOneAndUpdateOptions {
f.ArrayFilters = &filters
return f
}
// SetCollation specifies a Collation to use for the Find operation.
func (f *FindOneAndUpdateOptions) SetCollation(collation *Collation) *FindOneAndUpdateOptions {
f.Collation = collation
return f
}
// SetMaxTime specifies the max time to allow the query to run.
func (f *FindOneAndUpdateOptions) SetMaxTime(d time.Duration) *FindOneAndUpdateOptions {
f.MaxTime = &d
return f
}
// SetProjection adds an option to limit the fields returned for all documents.
func (f *FindOneAndUpdateOptions) SetProjection(projection interface{}) *FindOneAndUpdateOptions {
f.Projection = projection
return f
}
// SetReturnDocument specifies whether the original or updated document should be returned.
// If set to Before, the original document will be returned. If set to After, the updated document
// will be returned.
func (f *FindOneAndUpdateOptions) SetReturnDocument(rd ReturnDocument) *FindOneAndUpdateOptions {
f.ReturnDocument = &rd
return f
}
// SetSort specifies the order in which to return documents.
func (f *FindOneAndUpdateOptions) SetSort(sort interface{}) *FindOneAndUpdateOptions {
f.Sort = sort
return f
}
// SetUpsert specifies if a new document should be created if no document matches the query.
func (f *FindOneAndUpdateOptions) SetUpsert(b bool) *FindOneAndUpdateOptions {
f.Upsert = &b
return f
}
// MergeFindOneAndUpdateOptions combines the argued FindOneAndUpdateOptions 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
}
}
return fo
}
// FindOneAndDeleteOptions represent all possible options to the findOne() function.
type FindOneAndDeleteOptions struct {
Collation *Collation // Specifies a collation to be used
MaxTime *time.Duration // Specifies the maximum amount of time to allow the query to run.
Projection interface{} // Limits the fields returned for all documents.
Sort interface{} // Specifies the order in which to return results.
}
// FindOneAndDelete creates a new FindOneAndDeleteOptions instance.
func FindOneAndDelete() *FindOneAndDeleteOptions {
return &FindOneAndDeleteOptions{}
}
// SetCollation specifies a Collation to use for the Find operation.
// Valid for server versions >= 3.4
func (f *FindOneAndDeleteOptions) SetCollation(collation *Collation) *FindOneAndDeleteOptions {
f.Collation = collation
return f
}
// SetMaxTime specifies the max time to allow the query to run.
func (f *FindOneAndDeleteOptions) SetMaxTime(d time.Duration) *FindOneAndDeleteOptions {
f.MaxTime = &d
return f
}
// SetProjection adds an option to limit the fields returned for all documents.
func (f *FindOneAndDeleteOptions) SetProjection(projection interface{}) *FindOneAndDeleteOptions {
f.Projection = projection
return f
}
// SetSort specifies the order in which to return documents.
func (f *FindOneAndDeleteOptions) SetSort(sort interface{}) *FindOneAndDeleteOptions {
f.Sort = sort
return f
}
// MergeFindOneAndDeleteOptions combines the argued FindOneAndDeleteOptions 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
}
}
return fo
}