Class CollectionOptions
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
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Encapsulation of options applied to define collections change stream behaviour.static class
Options applicable to Time Series collections.static class
Encapsulation of ValidationOptions options. -
Method Summary
Modifier and TypeMethodDescriptioncapped()
Create newCollectionOptions
with already given settings and capped set to true.changeStream
(CollectionOptions.CollectionChangeStreamOptions changeStreamOptions) Create newCollectionOptions
with the givenCollectionOptions.TimeSeriesOptions
.Create newCollectionOptions
with already given settings andcollation
set to given value.Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.OFF
.static CollectionOptions
Quick way to set upCollectionOptions
for emitting (pre & post) change events.static CollectionOptions
empty()
Create new emptyCollectionOptions
.boolean
Create newCollectionOptions
with already given settings andvalidationAction
set toValidationAction.ERROR
.Get if the collection should be capped.Get theCollectionOptions.CollectionChangeStreamOptions
if available.Get theCollation
settings.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.TimeSeriesOptions
if available.Get theMongoJsonSchema
for the collection.int
hashCode()
static CollectionOptions
Create newCollectionOptions
by just providing theCollation
to use.maxDocuments
(long maxDocuments) Create newCollectionOptions
with already given settings andmaxDocuments
set to given value.Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.MODERATE
.schema
(MongoJsonSchema schema) Create newCollectionOptions
with already given settings andvalidationOptions
set to givenMongoJsonSchema
.schemaValidationAction
(com.mongodb.client.model.ValidationAction validationAction) Create newCollectionOptions
with already given settings andvalidationAction
set givenValidationAction
.schemaValidationLevel
(com.mongodb.client.model.ValidationLevel validationLevel) Create newCollectionOptions
with already given settings andvalidationLevel
set givenValidationLevel
.size
(long size) Create newCollectionOptions
with already given settings andsize
set to given value.Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.STRICT
.static CollectionOptions
timeSeries
(String timeField) Quick way to set upCollectionOptions
for a Time Series collection.static CollectionOptions
timeSeries
(String timeField, Function<CollectionOptions.TimeSeriesOptions, CollectionOptions.TimeSeriesOptions> options) Set upCollectionOptions
for a Time Series collection.timeSeries
(CollectionOptions.TimeSeriesOptions timeSeriesOptions) Create newCollectionOptions
with the givenCollectionOptions.TimeSeriesOptions
.toString()
validation
(CollectionOptions.ValidationOptions validationOptions) Create newCollectionOptions
with the givenCollectionOptions.ValidationOptions
.Create newCollectionOptions
with already given settings andvalidationOptions
set to givenValidator
.Create newCollectionOptions
with already given settings andvalidationAction
set toValidationAction.WARN
.
-
Method Details
-
just
Create newCollectionOptions
by just providing theCollation
to 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 upCollectionOptions
for 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 upCollectionOptions
for 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 upCollectionOptions
for emitting (pre & post) change events.- Returns:
- new instance of
CollectionOptions
. - Since:
- 4.0
- See Also:
-
capped
Create newCollectionOptions
with already given settings and capped set to true.
NOTE: Using capped collections requires definingsize(long)
.- Returns:
- new
CollectionOptions
. - Since:
- 2.0
-
maxDocuments
Create newCollectionOptions
with already given settings andmaxDocuments
set to given value.- Parameters:
maxDocuments
- can be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.0
-
size
Create newCollectionOptions
with already given settings andsize
set to given value.- Parameters:
size
- can be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.0
-
collation
Create newCollectionOptions
with already given settings andcollation
set to given value.- Parameters:
collation
- can be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.0
-
schema
Create newCollectionOptions
with already given settings andvalidationOptions
set to givenMongoJsonSchema
.- Parameters:
schema
- can be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
validator
Create newCollectionOptions
with already given settings andvalidationOptions
set to givenValidator
.- Parameters:
validator
- can be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
disableValidation
Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.OFF
.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
strictValidation
Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.STRICT
.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
moderateValidation
Create newCollectionOptions
with already given settings andvalidationLevel
set toValidationLevel.MODERATE
.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
warnOnValidationError
Create newCollectionOptions
with already given settings andvalidationAction
set toValidationAction.WARN
.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
failOnValidationError
Create newCollectionOptions
with already given settings andvalidationAction
set toValidationAction.ERROR
.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
schemaValidationLevel
public CollectionOptions schemaValidationLevel(com.mongodb.client.model.ValidationLevel validationLevel) Create newCollectionOptions
with already given settings andvalidationLevel
set givenValidationLevel
.- Parameters:
validationLevel
- must not be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
schemaValidationAction
public CollectionOptions schemaValidationAction(com.mongodb.client.model.ValidationAction validationAction) Create newCollectionOptions
with already given settings andvalidationAction
set givenValidationAction
.- Parameters:
validationAction
- must not be null.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
validation
Create newCollectionOptions
with the givenCollectionOptions.ValidationOptions
.- Parameters:
validationOptions
- must not be null. UseCollectionOptions.ValidationOptions.none()
to remove validation.- Returns:
- new
CollectionOptions
. - Since:
- 2.1
-
timeSeries
Create newCollectionOptions
with 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 newCollectionOptions
with the givenCollectionOptions.TimeSeriesOptions
.- Parameters:
changeStreamOptions
- must not be null.- Returns:
- new instance of
CollectionOptions
. - Since:
- 3.3
-
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 theCollation
settings.- Returns:
Optional.empty()
if not set.- Since:
- 2.0
-
getValidationOptions
Get theMongoJsonSchema
for the collection.- Returns:
Optional.empty()
if not set.- Since:
- 2.1
-
getTimeSeriesOptions
Get theCollectionOptions.TimeSeriesOptions
if available.- Returns:
Optional.empty()
if not specified.- Since:
- 3.3
-
getChangeStreamOptions
Get theCollectionOptions.CollectionChangeStreamOptions
if available.- Returns:
Optional.empty()
if not specified.- Since:
- 4.0
-
toString
-
equals
-
hashCode
public int hashCode()
-