You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

estimatedcountoptions.go 1.4 kB

5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142
  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. package options
  7. import "time"
  8. // EstimatedDocumentCountOptions represents all possible options to the EstimatedDocumentCount() function.
  9. type EstimatedDocumentCountOptions struct {
  10. MaxTime *time.Duration // The maximum amount of time to allow the operation to run
  11. }
  12. // EstimatedDocumentCount returns a pointer to a new EstimatedDocumentCountOptions
  13. func EstimatedDocumentCount() *EstimatedDocumentCountOptions {
  14. return &EstimatedDocumentCountOptions{}
  15. }
  16. // SetMaxTime specifies the maximum amount of time to allow the operation to run
  17. func (eco *EstimatedDocumentCountOptions) SetMaxTime(d time.Duration) *EstimatedDocumentCountOptions {
  18. eco.MaxTime = &d
  19. return eco
  20. }
  21. // MergeEstimatedDocumentCountOptions combines the given *EstimatedDocumentCountOptions into a single
  22. // *EstimatedDocumentCountOptions in a last one wins fashion.
  23. func MergeEstimatedDocumentCountOptions(opts ...*EstimatedDocumentCountOptions) *EstimatedDocumentCountOptions {
  24. e := EstimatedDocumentCount()
  25. for _, opt := range opts {
  26. if opt == nil {
  27. continue
  28. }
  29. if opt.MaxTime != nil {
  30. e.MaxTime = opt.MaxTime
  31. }
  32. }
  33. return e
  34. }