...

Source file src/go.mongodb.org/mongo-driver/mongo/options/estimatedcountoptions.go

Documentation: go.mongodb.org/mongo-driver/mongo/options

     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 "time"
    10  
    11  // EstimatedDocumentCountOptions represents options that can be used to configure an EstimatedDocumentCount operation.
    12  type EstimatedDocumentCountOptions struct {
    13  	// A string or document that will be included in server logs, profiling logs, and currentOp queries to help trace
    14  	// the operation.  The default is nil, which means that no comment will be included in the logs.
    15  	Comment interface{}
    16  
    17  	// The maximum amount of time that the query can run on the server. The default value is nil, meaning that there
    18  	// is no time limit for query execution.
    19  	//
    20  	// NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option may be used
    21  	// in its place to control the amount of time that a single operation can run before returning an error. MaxTime
    22  	// is ignored if Timeout is set on the client.
    23  	MaxTime *time.Duration
    24  }
    25  
    26  // EstimatedDocumentCount creates a new EstimatedDocumentCountOptions instance.
    27  func EstimatedDocumentCount() *EstimatedDocumentCountOptions {
    28  	return &EstimatedDocumentCountOptions{}
    29  }
    30  
    31  // SetComment sets the value for the Comment field.
    32  func (eco *EstimatedDocumentCountOptions) SetComment(comment interface{}) *EstimatedDocumentCountOptions {
    33  	eco.Comment = comment
    34  	return eco
    35  }
    36  
    37  // SetMaxTime sets the value for the MaxTime field.
    38  //
    39  // NOTE(benjirewis): MaxTime will be deprecated in a future release. The more general Timeout option
    40  // may be used in its place to control the amount of time that a single operation can run before
    41  // returning an error. MaxTime is ignored if Timeout is set on the client.
    42  func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions {
    43  	eco.MaxTime = &d
    44  	return eco
    45  }
    46  
    47  // MergeEstimatedDocumentCountOptions combines the given EstimatedDocumentCountOptions instances into a single
    48  // EstimatedDocumentCountOptions in a last-one-wins fashion.
    49  //
    50  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
    51  // single options struct instead.
    52  func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions {
    53  	e := EstimatedDocumentCount()
    54  	for _, opt := range opts {
    55  		if opt == nil {
    56  			continue
    57  		}
    58  		if opt.Comment != nil {
    59  			e.Comment = opt.Comment
    60  		}
    61  		if opt.MaxTime != nil {
    62  			e.MaxTime = opt.MaxTime
    63  		}
    64  	}
    65  
    66  	return e
    67  }
    68  

View as plain text