Don Newton | 379ae25 | 2019-04-01 12:17:06 -0400 | [diff] [blame^] | 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 | // ListCollectionsOptions represents all possible options for a listCollections command. |
| 10 | type ListCollectionsOptions struct { |
| 11 | NameOnly *bool // If true, only the collection names will be returned. |
| 12 | } |
| 13 | |
| 14 | // ListCollections creates a new *ListCollectionsOptions |
| 15 | func ListCollections() *ListCollectionsOptions { |
| 16 | return &ListCollectionsOptions{} |
| 17 | } |
| 18 | |
| 19 | // SetNameOnly specifies whether to return only the collection names. |
| 20 | func (lc *ListCollectionsOptions) SetNameOnly(b bool) *ListCollectionsOptions { |
| 21 | lc.NameOnly = &b |
| 22 | return lc |
| 23 | } |
| 24 | |
| 25 | // MergeListCollectionsOptions combines the given *ListCollectionsOptions into a single *ListCollectionsOptions in a |
| 26 | // last one wins fashion. |
| 27 | func MergeListCollectionsOptions(opts ...*ListCollectionsOptions) *ListCollectionsOptions { |
| 28 | lc := ListCollections() |
| 29 | for _, opt := range opts { |
| 30 | if opt == nil { |
| 31 | continue |
| 32 | } |
| 33 | if opt.NameOnly != nil { |
| 34 | lc.NameOnly = opt.NameOnly |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | return lc |
| 39 | } |