github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/deleteoptions.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  // DeleteOptions represents options that can be used to configure DeleteOne and DeleteMany operations.
    10  type DeleteOptions struct {
    11  	// Specifies a collation to use for string comparisons during the operation. This option is only valid for MongoDB
    12  	// versions >= 3.4. For previous server versions, the driver will return an error if this option is used. The
    13  	// default value is nil, which means the default collation of the collection will be used.
    14  	Collation *Collation
    15  
    16  	// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
    17  	// the operation.  The default value is nil, which means that no comment will be included in the logs.
    18  	Comment interface{}
    19  
    20  	// The index to use for the operation. This should either be the index name as a string or the index specification
    21  	// as a document. This option is only valid for MongoDB versions >= 4.4. Server versions >= 3.4 will return an error
    22  	// if this option is specified. For server versions < 3.4, the driver will return a client-side error if this option
    23  	// is specified. The driver will return an error if this option is specified during an unacknowledged write
    24  	// operation. The driver will return an error if the hint parameter is a multi-key map. The default value is nil,
    25  	// which means that no hint will be sent.
    26  	Hint interface{}
    27  
    28  	// Specifies parameters for the delete expression. This option is only valid for MongoDB versions >= 5.0. Older
    29  	// servers will report an error for using this option. This must be a document mapping parameter names to values.
    30  	// Values must be constant or closed expressions that do not reference document fields. Parameters can then be
    31  	// accessed as variables in an aggregate expression context (e.g. "$$var").
    32  	Let interface{}
    33  }
    34  
    35  // Delete creates a new DeleteOptions instance.
    36  func Delete() *DeleteOptions {
    37  	return &DeleteOptions{}
    38  }
    39  
    40  // SetCollation sets the value for the Collation field.
    41  func (do *DeleteOptions) SetCollation(c *Collation) *DeleteOptions {
    42  	do.Collation = c
    43  	return do
    44  }
    45  
    46  // SetComment sets the value for the Comment field.
    47  func (do *DeleteOptions) SetComment(comment interface{}) *DeleteOptions {
    48  	do.Comment = comment
    49  	return do
    50  }
    51  
    52  // SetHint sets the value for the Hint field.
    53  func (do *DeleteOptions) SetHint(hint interface{}) *DeleteOptions {
    54  	do.Hint = hint
    55  	return do
    56  }
    57  
    58  // SetLet sets the value for the Let field.
    59  func (do *DeleteOptions) SetLet(let interface{}) *DeleteOptions {
    60  	do.Let = let
    61  	return do
    62  }
    63  
    64  // MergeDeleteOptions combines the given DeleteOptions instances into a single DeleteOptions in a last-one-wins fashion.
    65  //
    66  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
    67  // single options struct instead.
    68  func MergeDeleteOptions(opts ...*DeleteOptions) *DeleteOptions {
    69  	dOpts := Delete()
    70  	for _, do := range opts {
    71  		if do == nil {
    72  			continue
    73  		}
    74  		if do.Collation != nil {
    75  			dOpts.Collation = do.Collation
    76  		}
    77  		if do.Comment != nil {
    78  			dOpts.Comment = do.Comment
    79  		}
    80  		if do.Hint != nil {
    81  			dOpts.Hint = do.Hint
    82  		}
    83  		if do.Let != nil {
    84  			dOpts.Let = do.Let
    85  		}
    86  	}
    87  
    88  	return dOpts
    89  }