github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/bulkwriteoptions.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  // DefaultOrdered is the default value for the Ordered option in BulkWriteOptions.
    10  var DefaultOrdered = true
    11  
    12  // BulkWriteOptions represents options that can be used to configure a BulkWrite operation.
    13  type BulkWriteOptions struct {
    14  	// If true, writes executed as part of the operation will opt out of document-level validation on the server. This
    15  	// option is valid for MongoDB versions >= 3.2 and is ignored for previous server versions. The default value is
    16  	// false. See https://www.mongodb.com/docs/manual/core/schema-validation/ for more information about document
    17  	// validation.
    18  	BypassDocumentValidation *bool
    19  
    20  	// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
    21  	// the operation.  The default value is nil, which means that no comment will be included in the logs.
    22  	Comment interface{}
    23  
    24  	// If true, no writes will be executed after one fails. The default value is true.
    25  	Ordered *bool
    26  
    27  	// Specifies parameters for all update and delete commands in the BulkWrite. This option is only valid for MongoDB
    28  	// versions >= 5.0. Older servers will report an error for using this option. This must be a document mapping
    29  	// parameter names to values. Values must be constant or closed expressions that do not reference document fields.
    30  	// Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var").
    31  	Let interface{}
    32  }
    33  
    34  // BulkWrite creates a new *BulkWriteOptions instance.
    35  func BulkWrite() *BulkWriteOptions {
    36  	return &BulkWriteOptions{
    37  		Ordered: &DefaultOrdered,
    38  	}
    39  }
    40  
    41  // SetComment sets the value for the Comment field.
    42  func (b *BulkWriteOptions) SetComment(comment interface{}) *BulkWriteOptions {
    43  	b.Comment = comment
    44  	return b
    45  }
    46  
    47  // SetOrdered sets the value for the Ordered field.
    48  func (b *BulkWriteOptions) SetOrdered(ordered bool) *BulkWriteOptions {
    49  	b.Ordered = &ordered
    50  	return b
    51  }
    52  
    53  // SetBypassDocumentValidation sets the value for the BypassDocumentValidation field.
    54  func (b *BulkWriteOptions) SetBypassDocumentValidation(bypass bool) *BulkWriteOptions {
    55  	b.BypassDocumentValidation = &bypass
    56  	return b
    57  }
    58  
    59  // SetLet sets the value for the Let field. Let specifies parameters for all update and delete commands in the BulkWrite.
    60  // This option is only valid for MongoDB versions >= 5.0. Older servers will report an error for using this option.
    61  // This must be a document mapping parameter names to values. Values must be constant or closed expressions that do not
    62  // reference document fields. Parameters can then be accessed as variables in an aggregate expression context (e.g. "$$var").
    63  func (b *BulkWriteOptions) SetLet(let interface{}) *BulkWriteOptions {
    64  	b.Let = &let
    65  	return b
    66  }
    67  
    68  // MergeBulkWriteOptions combines the given BulkWriteOptions instances into a single BulkWriteOptions in a last-one-wins
    69  // fashion.
    70  //
    71  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
    72  // single options struct instead.
    73  func MergeBulkWriteOptions(opts ...*BulkWriteOptions) *BulkWriteOptions {
    74  	b := BulkWrite()
    75  	for _, opt := range opts {
    76  		if opt == nil {
    77  			continue
    78  		}
    79  		if opt.Comment != nil {
    80  			b.Comment = opt.Comment
    81  		}
    82  		if opt.Ordered != nil {
    83  			b.Ordered = opt.Ordered
    84  		}
    85  		if opt.BypassDocumentValidation != nil {
    86  			b.BypassDocumentValidation = opt.BypassDocumentValidation
    87  		}
    88  		if opt.Let != nil {
    89  			b.Let = opt.Let
    90  		}
    91  	}
    92  
    93  	return b
    94  }