Interface MqlDocument

All Superinterfaces:
MqlValue

@Sealed @Beta(CLIENT) public interface MqlDocument extends MqlValue
A document 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 Details

    • hasField

      MqlBoolean hasField(String fieldName)
      Whether this document has a field with the provided fieldName (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

      MqlDocument setField(String fieldName, MqlValue value)
      Returns a document with the same fields as this document, but with the fieldName field set to the specified value.

      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

      MqlDocument unsetField(String fieldName)
      Returns a document with the same fields as this document, but excluding the field with the specified fieldName.

      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 provided fieldName.

      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 provided fieldName.

      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

      MqlBoolean getBoolean(String fieldName, MqlBoolean other)
      Returns the boolean value of the field with the provided fieldName, or the other value 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

      default MqlBoolean getBoolean(String fieldName, boolean other)
      Returns the boolean value of the field with the provided fieldName, or the other value 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 provided fieldName.

      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

      MqlNumber getNumber(String fieldName, MqlNumber other)
      Returns the number value of the field with the provided fieldName, or the other value 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

      default MqlNumber getNumber(String fieldName, Number other)
      Returns the number value of the field with the provided fieldName, or the other value 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 provided fieldName.

      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

      MqlInteger getInteger(String fieldName, MqlInteger other)
      Returns the integer value of the field with the provided fieldName, or the other value 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

      default MqlInteger getInteger(String fieldName, int other)
      Returns the integer value of the field with the provided fieldName, or the other value 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

      default MqlInteger getInteger(String fieldName, long other)
      Returns the integer value of the field with the provided fieldName, or the other value 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 provided fieldName.

      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

      MqlString getString(String fieldName, MqlString other)
      Returns the string value of the field with the provided fieldName, or the other value 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

      default MqlString getString(String fieldName, String other)
      Returns the string value of the field with the provided fieldName, or the other value 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 provided fieldName.

      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

      MqlDate getDate(String fieldName, MqlDate other)
      Returns the date value of the field with the provided fieldName, or the other value 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

      default MqlDate getDate(String fieldName, Instant other)
      Returns the date value of the field with the provided fieldName, or the other value 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

      Returns the document value of the field with the provided fieldName.

      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

      MqlDocument getDocument(String fieldName, MqlDocument other)
      Returns the document value of the field with the provided fieldName, or the other value 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

      default MqlDocument getDocument(String fieldName, Bson other)
      Returns the document value of the field with the provided fieldName, or the other value 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

      Returns the map value of the field with the provided fieldName.

      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 provided fieldName, or the other value 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 provided fieldName, or the other value 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

      Returns the array value of the field with the provided fieldName.

      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 provided fieldName, or the other value 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

      MqlDocument merge(MqlDocument other)
      Returns a document with the same fields as this document, but with any fields present in the other document 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

      <T extends MqlValue> MqlMap<@MqlUnchecked(TYPE_ARGUMENT) T> asMap()
      this document 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

      <R extends MqlValue> R passDocumentTo(Function<? super MqlDocument,? extends R> f)
      The result of passing this value to the provided function. Equivalent to f.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 to this value.
      Type Parameters:
      R - the type of the resulting value.
      Parameters:
      mapping - the switch mapping.
      Returns:
      the resulting value.
      See Also: