Interface MqlDocument
- All Superinterfaces:
MqlValue
value in the context of the MongoDB Query
Language (MQL). A document is a finite set of fields, where the field
name is a string, together with a value of any other
type in the type hierarchy.
No field name is repeated.- Since:
- 4.9.0
-
Method Summary
Modifier and TypeMethodDescription<T extends MqlValue>
MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T>asMap()thisdocument as a map.<T extends MqlValue>
@MqlUnchecked({PRESENT,TYPE}) MqlArray<@MqlUnchecked(TYPE_ARGUMENT) T>Returns the array value of the field with the providedfieldName.<T extends MqlValue>
MqlArray<@MqlUnchecked(TYPE_ARGUMENT) T>Returns the array value of the field with the providedfieldName, or theothervalue if the field is not an array or if the document hasField(java.lang.String) no such field.getBoolean(String fieldName) Returns the boolean value of the field with the providedfieldName.default MqlBooleangetBoolean(String fieldName, boolean other) Returns the boolean value of the field with the providedfieldName, or theothervalue if the field is not a boolean or if the document hasField(java.lang.String) no such field.getBoolean(String fieldName, MqlBoolean other) Returns the boolean value of the field with the providedfieldName, or theothervalue if the field is not a boolean or if the document hasField(java.lang.String) no such field.Returns the date value of the field with the providedfieldName.Returns the date value of the field with the providedfieldName, or theothervalue if the field is not a date or if the document hasField(java.lang.String) no such field.default MqlDateReturns the date value of the field with the providedfieldName, or theothervalue if the field is not a date or if the document hasField(java.lang.String) no such field.getDocument(String fieldName) Returns the document value of the field with the providedfieldName.getDocument(String fieldName, MqlDocument other) Returns the document value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a (child) document (or other document-like value.default MqlDocumentgetDocument(String fieldName, Bson other) Returns the document value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a (child) document (or other document-like value.Returns the MqlValue value of the field with the providedfieldName.getInteger(String fieldName) Returns the integer value of the field with the providedfieldName.default MqlIntegergetInteger(String fieldName, int other) Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.default MqlIntegergetInteger(String fieldName, long other) Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.getInteger(String fieldName, MqlInteger other) Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.<T extends MqlValue>
@MqlUnchecked({PRESENT,TYPE}) MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T>Returns the map value of the field with the providedfieldName.getMap(String fieldName, MqlMap<@MqlUnchecked(TYPE_ARGUMENT) ? extends T> other) Returns the map value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a map (or other MqlValue.isMapOr(com.mongodb.client.model.mql.MqlMap<? extends T>) map-like value}).default <T extends MqlValue>
MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T>Returns the map value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a map (or other MqlValue.isMapOr(com.mongodb.client.model.mql.MqlMap<? extends T>) map-like value}).Returns the number value of the field with the providedfieldName.Returns the number value of the field with the providedfieldName, or theothervalue if the field is not a number or if the document hasField(java.lang.String) no such field.default MqlNumberReturns the number value of the field with the providedfieldName, or theothervalue if the field is not a number or if the document hasField(java.lang.String) no such field.Returns the string value of the field with the providedfieldName.Returns the string value of the field with the providedfieldName, or theothervalue if the field is not a string or if the document hasField(java.lang.String) no such field.default MqlStringReturns the string value of the field with the providedfieldName, or theothervalue if the field is not a string or if the document hasField(java.lang.String) no such field.Whetherthisdocument has a field with the providedfieldName(if a field is set to null, it is present).merge(MqlDocument other) Returns a document with the same fields asthisdocument, but with any fields present in theotherdocument overwritten with the fields of that other document.<R extends MqlValue>
RpassDocumentTo(Function<? super MqlDocument, ? extends R> f) The result of passingthisvalue to the provided function.Returns a document with the same fields asthisdocument, but with thefieldNamefield set to the specifiedvalue.<R extends MqlValue>
RswitchDocumentOn(Function<Branches<MqlDocument>, ? extends BranchesTerminal<MqlDocument, ? extends R>> mapping) The result of applying the provided switch mapping tothisvalue.unsetField(String fieldName) Returns a document with the same fields asthisdocument, but excluding the field with the specifiedfieldName.Methods inherited from interface com.mongodb.client.model.mql.MqlValue
asString, eq, equals, gt, gte, isArrayOr, isBooleanOr, isDateOr, isDocumentOr, isIntegerOr, isMapOr, isNumberOr, isStringOr, lt, lte, ne, passTo, switchOn
-
Method Details
-
hasField
Whetherthisdocument has a field with the providedfieldName(if a field is set to null, it is present).- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
setField
Returns a document with the same fields asthisdocument, but with thefieldNamefield set to the specifiedvalue.This does not affect the original document.
Warning: Users should take care to assign values, such that the types of those values correspond to the types of ensuing
get...invocations, since this API has no way of verifying this correspondence.- Parameters:
fieldName- the name of the field.value- the value.- Returns:
- the resulting document.
- Since server release
- 5.0
-
unsetField
Returns a document with the same fields asthisdocument, but excluding the field with the specifiedfieldName.This does not affect the original document.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting document.
- Since server release
- 5.0
-
getField
Returns the MqlValue value of the field with the providedfieldName.Warning: Use of this method is an assertion that the document has the named field.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getBoolean
Returns the boolean value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getBoolean
Returns the boolean value of the field with the providedfieldName, or theothervalue if the field is not a boolean or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getBoolean
Returns the boolean value of the field with the providedfieldName, or theothervalue if the field is not a boolean or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getNumber
Returns the number value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getNumber
Returns the number value of the field with the providedfieldName, or theothervalue if the field is not a number or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getNumber
Returns the number value of the field with the providedfieldName, or theothervalue if the field is not a number or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getInteger
Returns the integer value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getInteger
Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getInteger
Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getInteger
Returns the integer value of the field with the providedfieldName, or theothervalue if the field is not an integer or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getString
Returns the string value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getString
Returns the string value of the field with the providedfieldName, or theothervalue if the field is not a string or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getString
Returns the string value of the field with the providedfieldName, or theothervalue if the field is not a string or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDate
Returns the date value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDate
Returns the date value of the field with the providedfieldName, or theothervalue if the field is not a date or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDate
Returns the date value of the field with the providedfieldName, or theothervalue if the field is not a date or if the document hasField(java.lang.String) no such field.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDocument
@MqlUnchecked({PRESENT,TYPE}) @MqlUnchecked({PRESENT,TYPE}) MqlDocument getDocument(String fieldName) Returns the document value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field and the field value is of the specified type.
- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDocument
Returns the document value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a (child) document (or other document-like value.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getDocument
Returns the document value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a (child) document (or other document-like value.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getMap
@MqlUnchecked({PRESENT,TYPE}) <T extends MqlValue> @MqlUnchecked({PRESENT,TYPE}) MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T> getMap(String fieldName) Returns the map value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field, and the field value is of the specified raw type, and the field value's type has the specified type argument.
- Type Parameters:
T- the type.- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getMap
<T extends MqlValue> MqlMap<T> getMap(String fieldName, MqlMap<@MqlUnchecked(TYPE_ARGUMENT) ? extends T> other) Returns the map value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a map (or other MqlValue.isMapOr(com.mongodb.client.model.mql.MqlMap<? extends T>) map-like value}).Warning: The type argument of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the type argument is correct.
- Type Parameters:
T- the type.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getMap
default <T extends MqlValue> MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T> getMap(String fieldName, Bson other) Returns the map value of the field with the providedfieldName, or theothervalue if the document hasField(java.lang.String) no such field, or if the specified field is not a map (or other MqlValue.isMapOr(com.mongodb.client.model.mql.MqlMap<? extends T>) map-like value}).Warning: The type argument of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the type argument is correct.
- Type Parameters:
T- the type.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getArray
@MqlUnchecked({PRESENT,TYPE}) <T extends MqlValue> @MqlUnchecked({PRESENT,TYPE}) MqlArray<@MqlUnchecked(TYPE_ARGUMENT) T> getArray(String fieldName) Returns the array value of the field with the providedfieldName.Warning: The type and presence of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the document has the named field, and the field value is of the specified raw type, and the field value's type has the specified type argument.
- Type Parameters:
T- the type.- Parameters:
fieldName- the name of the field.- Returns:
- the resulting value.
- Since server release
- 5.0
-
getArray
<T extends MqlValue> MqlArray<@MqlUnchecked(TYPE_ARGUMENT) T> getArray(String fieldName, MqlArray<? extends T> other) Returns the array value of the field with the providedfieldName, or theothervalue if the field is not an array or if the document hasField(java.lang.String) no such field.Warning: The type argument of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the type argument is correct.
- Type Parameters:
T- the type.- Parameters:
fieldName- the name of the field.other- the other value.- Returns:
- the resulting value.
- Since server release
- 5.0
-
merge
Returns a document with the same fields asthisdocument, but with any fields present in theotherdocument overwritten with the fields of that other document. That is, fields from both this and the other document are merged, with the other document having priority.This does not affect the original document.
- Parameters:
other- the other document.- Returns:
- the resulting value.
-
asMap
thisdocument as a map.Warning: The type argument of the resulting value is not enforced by the API. The use of this method is an unchecked assertion that the type argument is correct.
- Type Parameters:
T- the type.- Returns:
- the resulting value.
-
passDocumentTo
The result of passingthisvalue to the provided function. Equivalent tof.apply(this), and allows lambdas and static, user-defined functions to use the chaining syntax.- Type Parameters:
R- the type of the resulting value.- Parameters:
f- the function to apply.- Returns:
- the resulting value.
- See Also:
-
switchDocumentOn
<R extends MqlValue> R switchDocumentOn(Function<Branches<MqlDocument>, ? extends BranchesTerminal<MqlDocument, ? extends R>> mapping) The result of applying the provided switch mapping tothisvalue.- Type Parameters:
R- the type of the resulting value.- Parameters:
mapping- the switch mapping.- Returns:
- the resulting value.
- See Also:
-