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