blob: f43bb9f07081351056644455a77bd8dba4d3599e [file] [log] [blame]
Don Newton379ae252019-04-01 12:17:06 -04001// 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
7package options
8
9import "time"
10
11// EstimatedDocumentCountOptions represents all possible options to the estimatedDocumentCount() function
12type EstimatedDocumentCountOptions struct {
13 MaxTime *time.Duration // The maximum amount of time to allow the operation to run
14}
15
16// EstimatedDocumentCount returns a pointer to a new EstimatedDocumentCountOptions
17func EstimatedDocumentCount() *EstimatedDocumentCountOptions {
18 return &EstimatedDocumentCountOptions{}
19}
20
21// SetMaxTime specifies the maximum amount of time to allow the operation to run
22func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions {
23 eco.MaxTime = &d
24 return eco
25}
26
27// MergeEstimatedDocumentCountOptions combines the given *EstimatedDocumentCountOptions into a single
28// *EstimatedDocumentCountOptions in a last one wins fashion.
29func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions {
30 e := EstimatedDocumentCount()
31 for _, opt := range opts {
32 if opt == nil {
33 continue
34 }
35
36 if opt.MaxTime != nil {
37 e.MaxTime = opt.MaxTime
38 }
39 }
40
41 return e
42}