java.lang.Object
org.springframework.data.mongodb.core.CollectionOptions
Provides a simple wrapper to encapsulate the variety of settings you can use when creating a collection.
- Author:
- Thomas Risberg, Christoph Strobl, Mark Paluch, Andreas Zink, Ben Foster, Ross Lawley
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classEncapsulation of options applied to define collections change stream behaviour.static classEncapsulation of Encryption options for collections.static classOptions applicable to Time Series collections.static classEncapsulation of ValidationOptions options. -
Method Summary
Modifier and TypeMethodDescriptioncapped()Create newCollectionOptionswith already given settings and capped set to true.changeStream(CollectionOptions.CollectionChangeStreamOptions changeStreamOptions) Create newCollectionOptionswith the givenCollectionOptions.TimeSeriesOptions.Create newCollectionOptionswith already given settings andcollationset to given value.Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.OFF.static CollectionOptionsQuick way to set upCollectionOptionsfor emitting (pre & post) change events.static CollectionOptionsempty()Create new emptyCollectionOptions.encrypted(CollectionOptions.EncryptedFieldsOptions encryptedFieldsOptions) Set theCollectionOptions.EncryptedFieldsOptionsfor collections using queryable encryption.static CollectionOptionsencryptedCollection(Function<CollectionOptions.EncryptedFieldsOptions, CollectionOptions.EncryptedFieldsOptions> optionsFunction) Create newCollectionOptionsbuilding encryption options in a fluent style.static CollectionOptionsencryptedCollection(CollectionOptions.EncryptedFieldsOptions encryptedFieldsOptions) Create newCollectionOptionswith the givenencryptedFields.static CollectionOptionsencryptedCollection(MongoJsonSchema schema) Create newCollectionOptionsreading encryption options from the givenMongoJsonSchema.booleanCreate newCollectionOptionswith already given settings andvalidationActionset toValidationAction.ERROR.Get if the collection should be capped.Get theCollectionOptions.CollectionChangeStreamOptionsif available.Get theCollationsettings.Get theencryptedFieldsif available.Get the max number of documents the collection should be limited to.getSize()Get the size in bytes the collection should be limited to.Get theCollectionOptions.TimeSeriesOptionsif available.Get theMongoJsonSchemafor the collection.inthashCode()static CollectionOptionsCreate newCollectionOptionsby just providing theCollationto use.maxDocuments(long maxDocuments) Create newCollectionOptionswith already given settings andmaxDocumentsset to given value.Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.MODERATE.schema(MongoJsonSchema schema) Create newCollectionOptionswith already given settings andvalidationOptionsset to givenMongoJsonSchema.schemaValidationAction(com.mongodb.client.model.ValidationAction validationAction) Create newCollectionOptionswith already given settings andvalidationActionset givenValidationAction.schemaValidationLevel(com.mongodb.client.model.ValidationLevel validationLevel) Create newCollectionOptionswith already given settings andvalidationLevelset givenValidationLevel.size(long size) Create newCollectionOptionswith already given settings andsizeset to given value.Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.STRICT.static CollectionOptionstimeSeries(String timeField) Quick way to set upCollectionOptionsfor a Time Series collection.static CollectionOptionstimeSeries(String timeField, Function<CollectionOptions.TimeSeriesOptions, CollectionOptions.TimeSeriesOptions> options) Set upCollectionOptionsfor a Time Series collection.timeSeries(CollectionOptions.TimeSeriesOptions timeSeriesOptions) Create newCollectionOptionswith the givenCollectionOptions.TimeSeriesOptions.toString()validation(CollectionOptions.ValidationOptions validationOptions) Create newCollectionOptionswith the givenCollectionOptions.ValidationOptions.Create newCollectionOptionswith already given settings andvalidationOptionsset to givenValidator.Create newCollectionOptionswith already given settings andvalidationActionset toValidationAction.WARN.
-
Method Details
-
just
Create newCollectionOptionsby just providing theCollationto use.- Parameters:
collation- must not be null.- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
empty
Create new emptyCollectionOptions.- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
timeSeries
Quick way to set upCollectionOptionsfor a Time Series collection. For more advanced settings usetimeSeries(String, Function).- Parameters:
timeField- The name of the property which contains the date in each time series document. Must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 3.3
- See Also:
-
timeSeries
public static CollectionOptions timeSeries(String timeField, Function<CollectionOptions.TimeSeriesOptions, CollectionOptions.TimeSeriesOptions> options) Set upCollectionOptionsfor a Time Series collection.- Parameters:
timeField- the name of the field that contains the date in each time series document.options- a function to apply additional settings toCollectionOptions.TimeSeriesOptions.- Returns:
- new instance of
CollectionOptions. - Since:
- 4.4
-
emitChangedRevisions
Quick way to set upCollectionOptionsfor emitting (pre & post) change events.- Returns:
- new instance of
CollectionOptions. - Since:
- 4.0
- See Also:
-
encryptedCollection
@Contract("_ -> new") @CheckReturnValue public static CollectionOptions encryptedCollection(@Nullable CollectionOptions.EncryptedFieldsOptions encryptedFieldsOptions) Create newCollectionOptionswith the givenencryptedFields.- Parameters:
encryptedFieldsOptions- can be null- Returns:
- new instance of
CollectionOptions. - Since:
- 4.5.0
-
encryptedCollection
@Contract("_ -> new") @CheckReturnValue public static CollectionOptions encryptedCollection(MongoJsonSchema schema) Create newCollectionOptionsreading encryption options from the givenMongoJsonSchema.- Parameters:
schema- must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 4.5.0
-
encryptedCollection
@Contract("_ -> new") @CheckReturnValue public static CollectionOptions encryptedCollection(Function<CollectionOptions.EncryptedFieldsOptions, CollectionOptions.EncryptedFieldsOptions> optionsFunction) Create newCollectionOptionsbuilding encryption options in a fluent style.- Parameters:
optionsFunction- must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 4.5.0
-
capped
Create newCollectionOptionswith already given settings and capped set to true.
NOTE: Using capped collections requires definingsize(long).- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
maxDocuments
Create newCollectionOptionswith already given settings andmaxDocumentsset to given value.- Parameters:
maxDocuments- can be null.- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
size
Create newCollectionOptionswith already given settings andsizeset to given value.- Parameters:
size- can be null.- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
collation
Create newCollectionOptionswith already given settings andcollationset to given value.- Parameters:
collation- can be null.- Returns:
- new
CollectionOptions. - Since:
- 2.0
-
schema
Create newCollectionOptionswith already given settings andvalidationOptionsset to givenMongoJsonSchema.- Parameters:
schema- must not be null.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
validator
Create newCollectionOptionswith already given settings andvalidationOptionsset to givenValidator.- Parameters:
validator- can be null.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
disableValidation
Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.OFF.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
strictValidation
Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.STRICT.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
moderateValidation
Create newCollectionOptionswith already given settings andvalidationLevelset toValidationLevel.MODERATE.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
warnOnValidationError
Create newCollectionOptionswith already given settings andvalidationActionset toValidationAction.WARN.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
failOnValidationError
Create newCollectionOptionswith already given settings andvalidationActionset toValidationAction.ERROR.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
schemaValidationLevel
public CollectionOptions schemaValidationLevel(com.mongodb.client.model.ValidationLevel validationLevel) Create newCollectionOptionswith already given settings andvalidationLevelset givenValidationLevel.- Parameters:
validationLevel- must not be null.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
schemaValidationAction
public CollectionOptions schemaValidationAction(com.mongodb.client.model.ValidationAction validationAction) Create newCollectionOptionswith already given settings andvalidationActionset givenValidationAction.- Parameters:
validationAction- must not be null.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
validation
Create newCollectionOptionswith the givenCollectionOptions.ValidationOptions.- Parameters:
validationOptions- must not be null. UseCollectionOptions.ValidationOptions.none()to remove validation.- Returns:
- new
CollectionOptions. - Since:
- 2.1
-
timeSeries
Create newCollectionOptionswith the givenCollectionOptions.TimeSeriesOptions.- Parameters:
timeSeriesOptions- must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 3.3
-
changeStream
public CollectionOptions changeStream(CollectionOptions.CollectionChangeStreamOptions changeStreamOptions) Create newCollectionOptionswith the givenCollectionOptions.TimeSeriesOptions.- Parameters:
changeStreamOptions- must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 3.3
-
encrypted
@Contract("_ -> new") @CheckReturnValue public CollectionOptions encrypted(CollectionOptions.EncryptedFieldsOptions encryptedFieldsOptions) Set theCollectionOptions.EncryptedFieldsOptionsfor collections using queryable encryption.- Parameters:
encryptedFieldsOptions- must not be null.- Returns:
- new instance of
CollectionOptions. - Since:
- 4.5
-
getMaxDocuments
Get the max number of documents the collection should be limited to.- Returns:
Optional.empty()if not set.
-
getSize
Get the size in bytes the collection should be limited to.- Returns:
Optional.empty()if not set.
-
getCapped
Get if the collection should be capped.- Returns:
Optional.empty()if not set.- Since:
- 2.0
-
getCollation
Get theCollationsettings.- Returns:
Optional.empty()if not set.- Since:
- 2.0
-
getValidationOptions
Get theMongoJsonSchemafor the collection.- Returns:
Optional.empty()if not set.- Since:
- 2.1
-
getTimeSeriesOptions
Get theCollectionOptions.TimeSeriesOptionsif available.- Returns:
Optional.empty()if not specified.- Since:
- 3.3
-
getChangeStreamOptions
Get theCollectionOptions.CollectionChangeStreamOptionsif available.- Returns:
Optional.empty()if not specified.- Since:
- 4.0
-
getEncryptedFieldsOptions
Get theencryptedFieldsif available.- Returns:
Optional.empty()if not specified.- Since:
- 4.5
-
toString
-
equals
-
hashCode
public int hashCode()
-