Module spring.data.mongodb
Class ConvertOperators.Convert
java.lang.Object
org.springframework.data.mongodb.core.aggregation.ConvertOperators.Convert
- All Implemented Interfaces:
AggregationExpression,MongoExpression
- Enclosing class:
- ConvertOperators
AggregationExpression for $convert that converts a value to a specified type. NOTE: Requires MongoDB 4.0 or later.
- Since:
- 2.1
- Author:
- Christoph Strobl
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionappend(Object value, org.springframework.data.mongodb.core.aggregation.AbstractAggregationExpression.Expand expandList) Append the given key at the position in the underlyingLinkedHashMap.Get the argument map.protected booleanCheck if the given key is available.static ConvertOperators.ConvertconvertValue(Object value) Creates newConvertOperators.Convertusing the given value for the input attribute.static ConvertOperators.ConvertconvertValueOf(String fieldReference) Creates newConvertOperators.Convertusing the value of the providedfieldReferenceas input value.static ConvertOperators.ConvertconvertValueOf(AggregationExpression expression) Creates newConvertOperators.Convertusing the result of the providedexpressionas input value.protected <T> Tget(int index) Get the value at a given index.protected <T> TGet the value for a given key.protected Stringprotected booleanonErrorReturn(Object value) Optionally specify the value to return on encountering an error during conversion.onErrorReturnValueOf(String fieldReference) Optionally specify the field holding the value to return on encountering an error during conversion.onErrorReturnValueOf(AggregationExpression expression) Optionally specify the expression to evaluate and return on encountering an error during conversion.onNullReturn(Object value) Optionally specify the value to return when the input is null or missing.onNullReturnValueOf(String fieldReference) Optionally specify the field holding the value to return when the input is null or missing.onNullReturnValueOf(AggregationExpression expression) Optionally specify the expression to evaluate and return when the input is null or missing.to(int numericTypeIdentifier) Specify the conversion target type via its numeric representation.Specify the conversion target type via itsStringrepresentation.to(JsonSchemaObject.Type type) Specify the conversion target type.org.bson.DocumenttoDocument(Object value, AggregationOperationContext context) org.bson.DocumenttoDocument(AggregationOperationContext context) Specify the conversion target type via the value of the given field.toTypeOf(AggregationExpression expression) Specify the conversion target type via the value of the givenexpression.values()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.data.mongodb.core.aggregation.AggregationExpression
toDocument
-
Method Details
-
convertValue
Creates newConvertOperators.Convertusing the given value for the input attribute.- Parameters:
value- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
convertValueOf
Creates newConvertOperators.Convertusing the value of the providedfieldReferenceas input value.- Parameters:
fieldReference- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
convertValueOf
Creates newConvertOperators.Convertusing the result of the providedexpressionas input value.- Parameters:
expression- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
to
Specify the conversion target type via itsStringrepresentation.- double
- string
- objectId
- bool
- date
- int
- long
- decimal
- Parameters:
stringTypeIdentifier- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
to
Specify the conversion target type via its numeric representation.- 1
- double
- 2
- string
- 7
- objectId
- 8
- bool
- 9
- date
- 16
- int
- 18
- long
- 19
- decimal
- Parameters:
numericTypeIdentifier- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
to
Specify the conversion target type.- Parameters:
type- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
toTypeOf
Specify the conversion target type via the value of the given field.- Parameters:
fieldReference- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
toTypeOf
Specify the conversion target type via the value of the givenexpression.- Parameters:
expression- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onErrorReturn
Optionally specify the value to return on encountering an error during conversion.- Parameters:
value- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onErrorReturnValueOf
Optionally specify the field holding the value to return on encountering an error during conversion.- Parameters:
fieldReference- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onErrorReturnValueOf
Optionally specify the expression to evaluate and return on encountering an error during conversion.- Parameters:
expression- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onNullReturn
Optionally specify the value to return when the input is null or missing.- Parameters:
value- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onNullReturnValueOf
Optionally specify the field holding the value to return when the input is null or missing.- Parameters:
fieldReference- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
onNullReturnValueOf
Optionally specify the expression to evaluate and return when the input is null or missing.- Parameters:
expression- must not be null.- Returns:
- new instance of
ConvertOperators.Convert.
-
getMongoMethod
-
toDocument
Description copied from interface:AggregationExpression- Specified by:
toDocumentin interfaceAggregationExpression- Parameters:
context- must not be null.- Returns:
- the MongoDB native (
Document) form of the expression.
-
toDocument
-
asFields
-
append
-
append
-
append
-
appendTo
-
remove
-
appendAt
Append the given key at the position in the underlyingLinkedHashMap.- Parameters:
index-key-value-- Returns:
- Since:
- 3.1
-
values
-
get
protected <T> T get(int index) Get the value at a given index.- Type Parameters:
T-- Parameters:
index-- Returns:
- Since:
- 2.1
-
get
Get the value for a given key.- Type Parameters:
T-- Parameters:
key-- Returns:
- Since:
- 2.1
-
isArgumentMap
protected boolean isArgumentMap() -
argumentMap
Get the argument map.- Returns:
- Since:
- 2.1
-
contains
Check if the given key is available.- Parameters:
key-- Returns:
- Since:
- 2.1
-