github.com/mdaxf/iac@v0.0.0-20240519030858-58a061660378/vendor_skip/go.mongodb.org/mongo-driver/mongo/options/listcollectionsoptions.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  // ListCollectionsOptions represents options that can be used to configure a ListCollections operation.
    10  type ListCollectionsOptions struct {
    11  	// If true, each collection document will only contain a field for the collection name. The default value is false.
    12  	NameOnly *bool
    13  
    14  	// The maximum number of documents to be included in each batch returned by the server.
    15  	BatchSize *int32
    16  
    17  	// If true, and NameOnly is true, limits the documents returned to only contain collections the user is authorized to use. The default value
    18  	// is false. This option is only valid for MongoDB server versions >= 4.0. Server versions < 4.0 ignore this option.
    19  	AuthorizedCollections *bool
    20  }
    21  
    22  // ListCollections creates a new ListCollectionsOptions instance.
    23  func ListCollections() *ListCollectionsOptions {
    24  	return &ListCollectionsOptions{}
    25  }
    26  
    27  // SetNameOnly sets the value for the NameOnly field.
    28  func (lc *ListCollectionsOptions) SetNameOnly(b bool) *ListCollectionsOptions {
    29  	lc.NameOnly = &b
    30  	return lc
    31  }
    32  
    33  // SetBatchSize sets the value for the BatchSize field.
    34  func (lc *ListCollectionsOptions) SetBatchSize(size int32) *ListCollectionsOptions {
    35  	lc.BatchSize = &size
    36  	return lc
    37  }
    38  
    39  // SetAuthorizedCollections sets the value for the AuthorizedCollections field. This option is only valid for MongoDB server versions >= 4.0. Server
    40  // versions < 4.0 ignore this option.
    41  func (lc *ListCollectionsOptions) SetAuthorizedCollections(b bool) *ListCollectionsOptions {
    42  	lc.AuthorizedCollections = &b
    43  	return lc
    44  }
    45  
    46  // MergeListCollectionsOptions combines the given ListCollectionsOptions instances into a single *ListCollectionsOptions
    47  // in a last-one-wins fashion.
    48  //
    49  // Deprecated: Merging options structs will not be supported in Go Driver 2.0. Users should create a
    50  // single options struct instead.
    51  func MergeListCollectionsOptions(opts ...*ListCollectionsOptions) *ListCollectionsOptions {
    52  	lc := ListCollections()
    53  	for _, opt := range opts {
    54  		if opt == nil {
    55  			continue
    56  		}
    57  		if opt.NameOnly != nil {
    58  			lc.NameOnly = opt.NameOnly
    59  		}
    60  		if opt.BatchSize != nil {
    61  			lc.BatchSize = opt.BatchSize
    62  		}
    63  		if opt.AuthorizedCollections != nil {
    64  			lc.AuthorizedCollections = opt.AuthorizedCollections
    65  		}
    66  	}
    67  
    68  	return lc
    69  }