Package org.bson
Class Document
java.lang.Object
org.bson.Document
- All Implemented Interfaces:
Serializable,Map<String,,Object> Bson
@Deprecated(since="2022-10-31")
public class Document
extends Object
implements Map<String,Object>, Serializable, Bson
Deprecated.
Usage of this API is not supported in AEM as a Cloud Service.
A representation of a document as a
Map. All iterators will traverse the elements in insertion order, as with
LinkedHashMap.- Since:
- 3.0.0
- See Also:
-
Nested Class Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDocument()Deprecated.Creates an empty Document instance.Deprecated.Create a Document instance initialized with the given key/value pair.Deprecated.Creates a Document instance initialized with the given map. -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Put the given key/value pair into this Document and return this.voidclear()Deprecated.booleancontainsKey(Object key) Deprecated.booleancontainsValue(Object value) Deprecated.entrySet()Deprecated.booleanDeprecated.Deprecated.<T> TDeprecated.Gets the value of the given key, casting it to the givenClass<T>.<T> TDeprecated.Gets the value of the given key, casting it toClass<T>or returning the default value if null.getBoolean(Object key) Deprecated.Gets the value of the given key as a Boolean.booleangetBoolean(Object key, boolean defaultValue) Deprecated.Gets the value of the given key as a primitive boolean.Deprecated.Gets the value of the given key as a Date.Deprecated.Gets the value of the given key as a Double.<T> TgetEmbedded(List<?> keys, Class<T> clazz) Deprecated.Gets the value in an embedded document, casting it to the givenClass<T>.<T> TgetEmbedded(List<?> keys, T defaultValue) Deprecated.Gets the value in an embedded document, casting it to the givenClass<T>or returning the default value if null.getInteger(Object key) Deprecated.Gets the value of the given key as an Integer.intgetInteger(Object key, int defaultValue) Deprecated.Gets the value of the given key as a primitive int.<T> List<T> Deprecated.Gets the list value of the given key, casting the list elements to the givenClass<T>.<T> List<T> Deprecated.Gets the list value of the given key, casting the list elements toClass<T>or returning the default list value if null.Deprecated.Gets the value of the given key as a Long.getObjectId(Object key) Deprecated.Gets the value of the given key as an ObjectId.Deprecated.Gets the value of the given key as a String.inthashCode()Deprecated.booleanisEmpty()Deprecated.keySet()Deprecated.static DocumentDeprecated.Parses a string in MongoDB Extended JSON format to aDocumentstatic DocumentDeprecated.Parses a string in MongoDB Extended JSON format to aDocumentDeprecated.voidDeprecated.Deprecated.intsize()Deprecated.<C> BsonDocumenttoBsonDocument(Class<C> documentClass, CodecRegistry codecRegistry) Deprecated.Render the filter into a BsonDocument.toJson()Deprecated.Gets a JSON representation of this document using theJsonMode.STRICToutput mode, and otherwise the default settings ofJsonWriterSettings.BuilderandDocumentCodec.Deprecated.Gets a JSON representation of this documenttoJson(JsonWriterSettings writerSettings) Deprecated.Gets a JSON representation of this documenttoJson(JsonWriterSettings writerSettings, Encoder<Document> encoder) Deprecated.Gets a JSON representation of this documenttoString()Deprecated.values()Deprecated.Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
Document
public Document()Deprecated.Creates an empty Document instance. -
Document
Deprecated.Create a Document instance initialized with the given key/value pair.- Parameters:
key- keyvalue- value
-
Document
Deprecated.Creates a Document instance initialized with the given map.- Parameters:
map- initial map
-
-
Method Details
-
parse
Deprecated.Parses a string in MongoDB Extended JSON format to aDocument- Parameters:
json- the JSON string- Returns:
- a corresponding
Documentobject - See Also:
-
parse
Deprecated.Parses a string in MongoDB Extended JSON format to aDocument- Parameters:
json- the JSON stringdecoder- theDecoderto use to parse the JSON string into aDocument- Returns:
- a corresponding
Documentobject - See Also:
-
toBsonDocument
Deprecated.Description copied from interface:BsonRender the filter into a BsonDocument.- Specified by:
toBsonDocumentin interfaceBson- Type Parameters:
C- the type of the document class- Parameters:
documentClass- the document class in scope for the collection. This parameter may be ignored, but it may be used to alter the structure of the returnedBsonDocumentbased on some knowledge of the document class.codecRegistry- the codec registry. This parameter may be ignored, but it may be used to look upCodecinstances for the document class or any other related class.- Returns:
- the BsonDocument
-
append
Deprecated.Put the given key/value pair into this Document and return this. Useful for chaining puts in a single expression, e.g.doc.append("a", 1).append("b", 2)}- Parameters:
key- keyvalue- value- Returns:
- this
-
get
Deprecated.Gets the value of the given key, casting it to the givenClass<T>. This is useful to avoid having casts in client code, though the effect is the same. So to get the value of a key that is of type String, you would writeString name = doc.get("name", String.class)instead ofString name = (String) doc.get("x").- Type Parameters:
T- the type of the class- Parameters:
key- the keyclazz- the non-null class to cast the value to- Returns:
- the value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException- if the value of the given key is not of type T
-
get
Deprecated.Gets the value of the given key, casting it toClass<T>or returning the default value if null. This is useful to avoid having casts in client code, though the effect is the same.- Type Parameters:
T- the type of the class- Parameters:
key- the keydefaultValue- what to return if the value is null- Returns:
- the value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException- if the value of the given key is not of type T- Since:
- 3.5
-
getEmbedded
Deprecated.Gets the value in an embedded document, casting it to the givenClass<T>. The list of keys represents a path to the embedded value, drilling down into an embedded document for each key. This is useful to avoid having casts in client code, though the effect is the same. The generic type of the keys list is?to be consistent with the correspondinggetmethods, but in practice the actual type of the argument should beList<String>. So to get the embedded value of a key list that is of type String, you would writeString name = doc.getEmbedded(List.of("employee", "manager", "name"), String.class)instead ofString name = (String) doc.get("employee", Document.class).get("manager", Document.class).get("name").- Type Parameters:
T- the type of the class- Parameters:
keys- the list of keysclazz- the non-null class to cast the value to- Returns:
- the value of the given embedded key, or null if the instance does not contain this embedded key.
- Throws:
ClassCastException- if the value of the given embedded key is not of type T- Since:
- 3.10
-
getEmbedded
Deprecated.Gets the value in an embedded document, casting it to the givenClass<T>or returning the default value if null. The list of keys represents a path to the embedded value, drilling down into an embedded document for each key. This is useful to avoid having casts in client code, though the effect is the same. The generic type of the keys list is?to be consistent with the correspondinggetmethods, but in practice the actual type of the argument should beList<String>. So to get the embedded value of a key list that is of type String, you would writeString name = doc.getEmbedded(List.of("employee", "manager", "name"), "John Smith")instead ofString name = doc.get("employee", Document.class).get("manager", Document.class).get("name", "John Smith").- Type Parameters:
T- the type of the class- Parameters:
keys- the list of keysdefaultValue- what to return if the value is null- Returns:
- the value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException- if the value of the given key is not of type T- Since:
- 3.10
-
getInteger
Deprecated.Gets the value of the given key as an Integer.- Parameters:
key- the key- Returns:
- the value as an integer, which may be null
- Throws:
ClassCastException- if the value is not an integer
-
getInteger
Deprecated.Gets the value of the given key as a primitive int.- Parameters:
key- the keydefaultValue- what to return if the value is null- Returns:
- the value as an integer, which may be null
- Throws:
ClassCastException- if the value is not an integer
-
getLong
Deprecated.Gets the value of the given key as a Long.- Parameters:
key- the key- Returns:
- the value as a long, which may be null
- Throws:
ClassCastException- if the value is not an long
-
getDouble
Deprecated.Gets the value of the given key as a Double.- Parameters:
key- the key- Returns:
- the value as a double, which may be null
- Throws:
ClassCastException- if the value is not an double
-
getString
Deprecated.Gets the value of the given key as a String.- Parameters:
key- the key- Returns:
- the value as a String, which may be null
- Throws:
ClassCastException- if the value is not a String
-
getBoolean
Deprecated.Gets the value of the given key as a Boolean.- Parameters:
key- the key- Returns:
- the value as a Boolean, which may be null
- Throws:
ClassCastException- if the value is not an boolean
-
getBoolean
Deprecated.Gets the value of the given key as a primitive boolean.- Parameters:
key- the keydefaultValue- what to return if the value is null- Returns:
- the value as a primitive boolean
- Throws:
ClassCastException- if the value is not a boolean
-
getObjectId
Deprecated.Gets the value of the given key as an ObjectId.- Parameters:
key- the key- Returns:
- the value as an ObjectId, which may be null
- Throws:
ClassCastException- if the value is not an ObjectId
-
getDate
Deprecated.Gets the value of the given key as a Date.- Parameters:
key- the key- Returns:
- the value as a Date, which may be null
- Throws:
ClassCastException- if the value is not a Date
-
getList
Deprecated.Gets the list value of the given key, casting the list elements to the givenClass<T>. This is useful to avoid having casts in client code, though the effect is the same.- Type Parameters:
T- the type of the class- Parameters:
key- the keyclazz- the non-null class to cast the list value to- Returns:
- the list value of the given key, or null if the instance does not contain this key.
- Throws:
ClassCastException- if the elements in the list value of the given key is not of type T or the value is not a list- Since:
- 3.10
-
getList
Deprecated.Gets the list value of the given key, casting the list elements toClass<T>or returning the default list value if null. This is useful to avoid having casts in client code, though the effect is the same.- Type Parameters:
T- the type of the class- Parameters:
key- the keyclazz- the non-null class to cast the list value todefaultValue- what to return if the value is null- Returns:
- the list value of the given key, or the default list value if the instance does not contain this key.
- Throws:
ClassCastException- if the value of the given key is not of type T- Since:
- 3.10
-
toJson
Deprecated.Gets a JSON representation of this document using theJsonMode.STRICToutput mode, and otherwise the default settings ofJsonWriterSettings.BuilderandDocumentCodec.- Returns:
- a JSON representation of this document
- Throws:
CodecConfigurationException- if the document contains types not in the default registry- See Also:
-
toJson
Deprecated.Gets a JSON representation of this documentWith the default
DocumentCodec.- Parameters:
writerSettings- the json writer settings to use when encoding- Returns:
- a JSON representation of this document
- Throws:
CodecConfigurationException- if the document contains types not in the default registry
-
toJson
Deprecated.Gets a JSON representation of this documentWith the default
JsonWriterSettings.- Parameters:
encoder- the document codec instance to use to encode the document- Returns:
- a JSON representation of this document
- Throws:
CodecConfigurationException- if the registry does not contain a codec for the document values.
-
toJson
Deprecated.Gets a JSON representation of this document- Parameters:
writerSettings- the json writer settings to use when encodingencoder- the document codec instance to use to encode the document- Returns:
- a JSON representation of this document
- Throws:
CodecConfigurationException- if the registry does not contain a codec for the document values.
-
size
public int size()Deprecated. -
isEmpty
public boolean isEmpty()Deprecated. -
containsValue
Deprecated.- Specified by:
containsValuein interfaceMap<String,Object>
-
containsKey
Deprecated.- Specified by:
containsKeyin interfaceMap<String,Object>
-
get
Deprecated. -
put
Deprecated. -
remove
Deprecated. -
putAll
Deprecated. -
clear
public void clear()Deprecated. -
keySet
Deprecated. -
values
Deprecated. -
entrySet
Deprecated. -
equals
Deprecated. -
hashCode
public int hashCode()Deprecated. -
toString
Deprecated.
-