public class BsonDocument extends BsonValue implements Map<String,BsonValue>, Cloneable, Bson, Serializable
Constructor and Description |
---|
BsonDocument()
Construct an empty document.
|
BsonDocument(List<BsonElement> bsonElements)
Construct a new instance with the given list
BsonElement , none of which may be null. |
BsonDocument(String key,
BsonValue value)
Construct a new instance with a single key value pair
|
Modifier and Type | Method and Description |
---|---|
BsonDocument |
append(String key,
BsonValue value)
Put the given key and value into this document, and return the document.
|
void |
clear() |
BsonDocument |
clone() |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value) |
Set<Map.Entry<String,BsonValue>> |
entrySet() |
boolean |
equals(Object o) |
BsonValue |
get(Object key) |
BsonValue |
get(Object key,
BsonValue defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonArray |
getArray(Object key)
Gets the value of the key if it is a BsonArray, or throws if not.
|
BsonArray |
getArray(Object key,
BsonArray defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonBinary |
getBinary(Object key)
Gets the value of the key if it is a BsonBinary, or throws if not.
|
BsonBinary |
getBinary(Object key,
BsonBinary defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonBoolean |
getBoolean(Object key)
Gets the value of the key if it is a BsonBoolean, or throws if not.
|
BsonBoolean |
getBoolean(Object key,
BsonBoolean defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonType |
getBsonType()
Gets the BSON type of this value.
|
BsonDateTime |
getDateTime(Object key)
Gets the value of the key if it is a BsonDateTime, or throws if not.
|
BsonDateTime |
getDateTime(Object key,
BsonDateTime defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDecimal128 |
getDecimal128(Object key)
Gets the value of the key if it is a BsonDecimal128, or throws if not.
|
BsonDecimal128 |
getDecimal128(Object key,
BsonDecimal128 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDocument |
getDocument(Object key)
Gets the value of the key if it is a BsonDocument, or throws if not.
|
BsonDocument |
getDocument(Object key,
BsonDocument defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDouble |
getDouble(Object key)
Gets the value of the key if it is a BsonDouble, or throws if not.
|
BsonDouble |
getDouble(Object key,
BsonDouble defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonInt32 |
getInt32(Object key)
Gets the value of the key if it is a BsonInt32, or throws if not.
|
BsonInt32 |
getInt32(Object key,
BsonInt32 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonInt64 |
getInt64(Object key)
Gets the value of the key if it is a BsonInt64, or throws if not.
|
BsonInt64 |
getInt64(Object key,
BsonInt64 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonNumber |
getNumber(Object key)
Gets the value of the key if it is a BsonNumber, or throws if not.
|
BsonNumber |
getNumber(Object key,
BsonNumber defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonObjectId |
getObjectId(Object key)
Gets the value of the key if it is a BsonObjectId, or throws if not.
|
BsonObjectId |
getObjectId(Object key,
BsonObjectId defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonRegularExpression |
getRegularExpression(Object key)
Gets the value of the key if it is a BsonRegularExpression, or throws if not.
|
BsonRegularExpression |
getRegularExpression(Object key,
BsonRegularExpression defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonString |
getString(Object key)
Gets the value of the key if it is a BsonString, or throws if not.
|
BsonString |
getString(Object key,
BsonString defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonTimestamp |
getTimestamp(Object key)
Gets the value of the key if it is a BsonTimestamp, or throws if not.
|
BsonTimestamp |
getTimestamp(Object key,
BsonTimestamp defaultValue)
If the document does not contain the given key, return the given default value.
|
int |
hashCode() |
boolean |
isArray(Object key)
Returns true if the value of the key is a BsonArray, returns false if the document does not contain the key.
|
boolean |
isBinary(Object key)
Returns true if the value of the key is a BsonBinary, returns false if the document does not contain the key.
|
boolean |
isBoolean(Object key)
Returns true if the value of the key is a BsonBoolean, returns false if the document does not contain the key.
|
boolean |
isDateTime(Object key)
Returns true if the value of the key is a BsonDateTime, returns false if the document does not contain the key.
|
boolean |
isDecimal128(Object key)
Returns true if the value of the key is a BsonDecimal128, returns false if the document does not contain the key.
|
boolean |
isDocument(Object key)
Returns true if the value of the key is a BsonDocument, returns false if the document does not contain the key.
|
boolean |
isDouble(Object key)
Returns true if the value of the key is a BsonDouble, returns false if the document does not contain the key.
|
boolean |
isEmpty() |
boolean |
isInt32(Object key)
Returns true if the value of the key is a BsonInt32, returns false if the document does not contain the key.
|
boolean |
isInt64(Object key)
Returns true if the value of the key is a BsonInt64, returns false if the document does not contain the key.
|
boolean |
isNull(Object key)
Returns true if the value of the key is a BsonNull, returns false if the document does not contain the key.
|
boolean |
isNumber(Object key)
Returns true if the value of the key is a BsonNumber, returns false if the document does not contain the key.
|
boolean |
isObjectId(Object key)
Returns true if the value of the key is a BsonObjectId, returns false if the document does not contain the key.
|
boolean |
isString(Object key)
Returns true if the value of the key is a BsonString, returns false if the document does not contain the key.
|
boolean |
isTimestamp(Object key)
Returns true if the value of the key is a BsonTimestamp, returns false if the document does not contain the key.
|
Set<String> |
keySet() |
static BsonDocument |
parse(String json)
Parses a string in MongoDB Extended JSON format to a
BsonDocument |
BsonValue |
put(String key,
BsonValue value) |
void |
putAll(Map<? extends String,? extends BsonValue> m) |
BsonValue |
remove(Object key) |
int |
size() |
<C> BsonDocument |
toBsonDocument(Class<C> documentClass,
CodecRegistry codecRegistry)
Render the filter into a BsonDocument.
|
String |
toJson()
Gets a JSON representation of this document using the default settings of
JsonWriterSettings . |
String |
toJson(JsonWriterSettings settings)
Gets a JSON representation of this document using the given
JsonWriterSettings . |
String |
toString() |
Collection<BsonValue> |
values() |
asArray, asBinary, asBoolean, asDateTime, asDBPointer, asDecimal128, asDocument, asDouble, asInt32, asInt64, asJavaScript, asJavaScriptWithScope, asNumber, asObjectId, asRegularExpression, asString, asSymbol, asTimestamp, isArray, isBinary, isBoolean, isDateTime, isDBPointer, isDecimal128, isDocument, isDouble, isInt32, isInt64, isJavaScript, isJavaScriptWithScope, isNull, isNumber, isObjectId, isRegularExpression, isString, isSymbol, isTimestamp
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
public BsonDocument(List<BsonElement> bsonElements)
BsonElement
, none of which may be null.bsonElements
- a list of BsonElement
public BsonDocument(String key, BsonValue value)
key
- the keyvalue
- the valuepublic BsonDocument()
public static BsonDocument parse(String json)
BsonDocument
json
- the JSON stringBsonDocument
objectJsonReader
public <C> BsonDocument toBsonDocument(Class<C> documentClass, CodecRegistry codecRegistry)
Bson
toBsonDocument
in interface Bson
C
- the type of the document classdocumentClass
- the document class in scope for the collection. This parameter may be ignored, but it may be used to alter
the structure of the returned BsonDocument
based on some knowledge of the document class.codecRegistry
- the codec registry. This parameter may be ignored, but it may be used to look up Codec
instances for
the document class or any other related class.public BsonType getBsonType()
BsonValue
getBsonType
in class BsonValue
public boolean containsKey(Object key)
containsKey
in interface Map<String,BsonValue>
public boolean containsValue(Object value)
containsValue
in interface Map<String,BsonValue>
public BsonDocument getDocument(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not a BsonDocumentpublic BsonArray getArray(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonNumber getNumber(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonInt32 getInt32(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonInt64 getInt64(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDecimal128 getDecimal128(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDouble getDouble(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonBoolean getBoolean(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonString getString(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDateTime getDateTime(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonTimestamp getTimestamp(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonObjectId getObjectId(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonRegularExpression getRegularExpression(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonBinary getBinary(Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic boolean isNull(Object key)
key
- the keypublic boolean isDocument(Object key)
key
- the keypublic boolean isArray(Object key)
key
- the keypublic boolean isNumber(Object key)
key
- the keypublic boolean isInt32(Object key)
key
- the keypublic boolean isInt64(Object key)
key
- the keypublic boolean isDecimal128(Object key)
key
- the keypublic boolean isDouble(Object key)
key
- the keypublic boolean isBoolean(Object key)
key
- the keypublic boolean isString(Object key)
key
- the keypublic boolean isDateTime(Object key)
key
- the keypublic boolean isTimestamp(Object key)
key
- the keypublic boolean isObjectId(Object key)
key
- the keypublic boolean isBinary(Object key)
key
- the keypublic BsonValue get(Object key, BsonValue defaultValue)
key
- the keydefaultValue
- the default valuepublic BsonDocument getDocument(Object key, BsonDocument defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonArray getArray(Object key, BsonArray defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonNumber getNumber(Object key, BsonNumber defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonInt32 getInt32(Object key, BsonInt32 defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonInt64 getInt64(Object key, BsonInt64 defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonDecimal128 getDecimal128(Object key, BsonDecimal128 defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonDouble getDouble(Object key, BsonDouble defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonBoolean getBoolean(Object key, BsonBoolean defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonString getString(Object key, BsonString defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonDateTime getDateTime(Object key, BsonDateTime defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonTimestamp getTimestamp(Object key, BsonTimestamp defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonObjectId getObjectId(Object key, BsonObjectId defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonBinary getBinary(Object key, BsonBinary defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic BsonRegularExpression getRegularExpression(Object key, BsonRegularExpression defaultValue)
key
- the keydefaultValue
- the default valueBsonInvalidOperationException
- if the document contains the key but the value is not of the expected typepublic Collection<BsonValue> values()
public BsonDocument append(String key, BsonValue value)
key
- the keyvalue
- the valuepublic boolean equals(Object o)
public int hashCode()
public String toJson()
JsonWriterSettings
.JsonWriterSettings
public String toJson(JsonWriterSettings settings)
JsonWriterSettings
.settings
- the JSON writer settingspublic BsonDocument clone()