// Copyright (C) MongoDB, Inc. 2017-present. // // Licensed under the Apache License, Version 2.0 (the "License"); you may // not use this file except in compliance with the License. You may obtain // a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 package options import ( "time" ) // DefaultIndexOptions represents the default arguments for a collection to // apply on new indexes. This type can be used when creating a new collection // through the CreateCollectionOptions.SetDefaultIndexOptions method. // // See corresponding setter methods for documentation. type DefaultIndexOptions struct { StorageEngine any } // DefaultIndexOptionsBuilder contains options to configure default index // operations. Each option can be set through setter functions. See // documentation for each setter function for an explanation of the option. type DefaultIndexOptionsBuilder struct { Opts []func(*DefaultIndexOptions) error } // DefaultIndex creates a new DefaultIndexOptions instance. func DefaultIndex() *DefaultIndexOptionsBuilder { return &DefaultIndexOptionsBuilder{} } // List returns a list of DefaultIndexOptions setter functions. func (d *DefaultIndexOptionsBuilder) List() []func(*DefaultIndexOptions) error { return d.Opts } // SetStorageEngine sets the value for the StorageEngine field. Specifies the storage engine to use for // the index. The value must be a document in the form {: }. The default // value is nil, which means that the default storage engine will be used. func (d *DefaultIndexOptionsBuilder) SetStorageEngine(storageEngine any) *DefaultIndexOptionsBuilder { d.Opts = append(d.Opts, func(opts *DefaultIndexOptions) error { opts.StorageEngine = storageEngine return nil }) return d } // TimeSeriesOptions specifies arguments on a time-series collection. // // See corresponding setter methods for documentation. type TimeSeriesOptions struct { TimeField string MetaField *string Granularity *string BucketMaxSpan *time.Duration BucketRounding *time.Duration } // TimeSeriesOptionsBuilder contains options to configure timeseries operations. // Each option can be set through setter functions. See documentation for each // setter function for an explanation of the option. type TimeSeriesOptionsBuilder struct { Opts []func(*TimeSeriesOptions) error } // TimeSeries creates a new TimeSeriesOptions instance. func TimeSeries() *TimeSeriesOptionsBuilder { return &TimeSeriesOptionsBuilder{} } // List returns a list of TimeSeriesOptions setter functions. func (tso *TimeSeriesOptionsBuilder) List() []func(*TimeSeriesOptions) error { return tso.Opts } // SetTimeField sets the value for the TimeField. TimeField is the top-level field to be used // for time. Inserted documents must have this field, and the field must be of the BSON UTC // datetime type (0x9). func (tso *TimeSeriesOptionsBuilder) SetTimeField(timeField string) *TimeSeriesOptionsBuilder { tso.Opts = append(tso.Opts, func(opts *TimeSeriesOptions) error { opts.TimeField = timeField return nil }) return tso } // SetMetaField sets the value for the MetaField. MetaField is the name of the top-level field // describing the series. This field is used to group related data and may be of any BSON type, // except for array. This name may not be the same as the TimeField or _id. This field is optional. func (tso *TimeSeriesOptionsBuilder) SetMetaField(metaField string) *TimeSeriesOptionsBuilder { tso.Opts = append(tso.Opts, func(opts *TimeSeriesOptions) error { opts.MetaField = &metaField return nil }) return tso } // SetGranularity sets the value for Granularity. Granularity is the granularity of time-series data. // Allowed granularity options are "seconds", "minutes" and "hours". This field is optional. func (tso *TimeSeriesOptionsBuilder) SetGranularity(granularity string) *TimeSeriesOptionsBuilder { tso.Opts = append(tso.Opts, func(opts *TimeSeriesOptions) error { opts.Granularity = &granularity return nil }) return tso } // SetBucketMaxSpan sets the value for BucketMaxSpan. BucketMaxSpan is the maximum range of time // values for a bucket. The time.Duration is rounded down to the nearest second and applied as // the command option: "bucketRoundingSeconds". This field is optional. func (tso *TimeSeriesOptionsBuilder) SetBucketMaxSpan(dur time.Duration) *TimeSeriesOptionsBuilder { tso.Opts = append(tso.Opts, func(opts *TimeSeriesOptions) error { opts.BucketMaxSpan = &dur return nil }) return tso } // SetBucketRounding sets the value for BucketRounding. BucketRounding is used to determine the // minimum time boundary when opening a new bucket by rounding the first timestamp down to the next // multiple of this value. The time.Duration is rounded down to the nearest second and applied as // the command option: "bucketRoundingSeconds". This field is optional. func (tso *TimeSeriesOptionsBuilder) SetBucketRounding(dur time.Duration) *TimeSeriesOptionsBuilder { tso.Opts = append(tso.Opts, func(opts *TimeSeriesOptions) error { opts.BucketRounding = &dur return nil }) return tso } // CreateCollectionOptions represents arguments that can be used to configure a // CreateCollection operation. // // See corresponding setter methods for documentation. type CreateCollectionOptions struct { Capped *bool Collation *Collation ChangeStreamPreAndPostImages any DefaultIndexOptions *DefaultIndexOptionsBuilder MaxDocuments *int64 SizeInBytes *int64 StorageEngine any ValidationAction *string ValidationLevel *string Validator any ExpireAfterSeconds *int64 TimeSeriesOptions *TimeSeriesOptionsBuilder EncryptedFields any ClusteredIndex any } // CreateCollectionOptionsBuilder contains options to configure a new // collection. Each option can be set through setter functions. See // documentation for each setter function for an explanation of the option. type CreateCollectionOptionsBuilder struct { Opts []func(*CreateCollectionOptions) error } // CreateCollection creates a new CreateCollectionOptions instance. func CreateCollection() *CreateCollectionOptionsBuilder { return &CreateCollectionOptionsBuilder{} } // List returns a list of CreateCollectionOptions setter functions. func (c *CreateCollectionOptionsBuilder) List() []func(*CreateCollectionOptions) error { return c.Opts } // SetCapped sets the value for the Capped field. Specifies if the collection is capped // (see https://www.mongodb.com/docs/manual/core/capped-collections/). If true, the SizeInBytes // option must also be specified. The default value is false. func (c *CreateCollectionOptionsBuilder) SetCapped(capped bool) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.Capped = &capped return nil }) return c } // SetCollation sets the value for the Collation field. Specifies the default // collation for the new collection. The default value is nil. func (c *CreateCollectionOptionsBuilder) SetCollation(collation *Collation) *CreateCollectionOptionsBuilder { c.Opts = append(c.Opts, func(opts *CreateCollectionOptions) error { opts.Collation = collation return nil }) return c } // SetChangeStreamPreAndPostImages sets the value for the ChangeStreamPreAndPostImages field. // Specifies how change streams opened against the collection can return pre- and post-images of // updated documents. The value must be a document in the form {