public class BsonDocument extends BsonValue implements java.util.Map<java.lang.String,BsonValue>, java.lang.Cloneable, Bson, java.io.Serializable
Constructor and Description |
---|
BsonDocument()
Construct an empty document.
|
BsonDocument(java.util.List<BsonElement> bsonElements)
Construct a new instance with the given list
BsonElement , none of which may be null. |
BsonDocument(java.lang.String key,
BsonValue value)
Construct a new instance with a single key value pair
|
Modifier and Type | Method and Description |
---|---|
BsonDocument |
append(java.lang.String key,
BsonValue value)
Put the given key and value into this document, and return the document.
|
void |
clear() |
BsonDocument |
clone() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,BsonValue>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
BsonValue |
get(java.lang.Object key) |
BsonValue |
get(java.lang.Object key,
BsonValue defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonArray |
getArray(java.lang.Object key)
Gets the value of the key if it is a BsonArray, or throws if not.
|
BsonArray |
getArray(java.lang.Object key,
BsonArray defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonBinary |
getBinary(java.lang.Object key)
Gets the value of the key if it is a BsonBinary, or throws if not.
|
BsonBinary |
getBinary(java.lang.Object key,
BsonBinary defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonBoolean |
getBoolean(java.lang.Object key)
Gets the value of the key if it is a BsonBoolean, or throws if not.
|
BsonBoolean |
getBoolean(java.lang.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(java.lang.Object key)
Gets the value of the key if it is a BsonDateTime, or throws if not.
|
BsonDateTime |
getDateTime(java.lang.Object key,
BsonDateTime defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDecimal128 |
getDecimal128(java.lang.Object key)
Gets the value of the key if it is a BsonDecimal128, or throws if not.
|
BsonDecimal128 |
getDecimal128(java.lang.Object key,
BsonDecimal128 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDocument |
getDocument(java.lang.Object key)
Gets the value of the key if it is a BsonDocument, or throws if not.
|
BsonDocument |
getDocument(java.lang.Object key,
BsonDocument defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonDouble |
getDouble(java.lang.Object key)
Gets the value of the key if it is a BsonDouble, or throws if not.
|
BsonDouble |
getDouble(java.lang.Object key,
BsonDouble defaultValue)
If the document does not contain the given key, return the given default value.
|
java.lang.String |
getFirstKey()
Gets the first key in the document.
|
BsonInt32 |
getInt32(java.lang.Object key)
Gets the value of the key if it is a BsonInt32, or throws if not.
|
BsonInt32 |
getInt32(java.lang.Object key,
BsonInt32 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonInt64 |
getInt64(java.lang.Object key)
Gets the value of the key if it is a BsonInt64, or throws if not.
|
BsonInt64 |
getInt64(java.lang.Object key,
BsonInt64 defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonNumber |
getNumber(java.lang.Object key)
Gets the value of the key if it is a BsonNumber, or throws if not.
|
BsonNumber |
getNumber(java.lang.Object key,
BsonNumber defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonObjectId |
getObjectId(java.lang.Object key)
Gets the value of the key if it is a BsonObjectId, or throws if not.
|
BsonObjectId |
getObjectId(java.lang.Object key,
BsonObjectId defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonRegularExpression |
getRegularExpression(java.lang.Object key)
Gets the value of the key if it is a BsonRegularExpression, or throws if not.
|
BsonRegularExpression |
getRegularExpression(java.lang.Object key,
BsonRegularExpression defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonString |
getString(java.lang.Object key)
Gets the value of the key if it is a BsonString, or throws if not.
|
BsonString |
getString(java.lang.Object key,
BsonString defaultValue)
If the document does not contain the given key, return the given default value.
|
BsonTimestamp |
getTimestamp(java.lang.Object key)
Gets the value of the key if it is a BsonTimestamp, or throws if not.
|
BsonTimestamp |
getTimestamp(java.lang.Object key,
BsonTimestamp defaultValue)
If the document does not contain the given key, return the given default value.
|
int |
hashCode() |
boolean |
isArray(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.Object key)
Returns true if the value of the key is a BsonTimestamp, returns false if the document does not contain the key.
|
java.util.Set<java.lang.String> |
keySet() |
static BsonDocument |
parse(java.lang.String json)
Parses a string in MongoDB Extended JSON format to a
BsonDocument |
BsonValue |
put(java.lang.String key,
BsonValue value) |
void |
putAll(java.util.Map<? extends java.lang.String,? extends BsonValue> m) |
BsonValue |
remove(java.lang.Object key) |
int |
size() |
<C> BsonDocument |
toBsonDocument(java.lang.Class<C> documentClass,
CodecRegistry codecRegistry)
Render the filter into a BsonDocument.
|
java.lang.String |
toJson()
Gets a JSON representation of this document using the
JsonMode.STRICT output mode, and otherwise the default
settings of JsonWriterSettings.Builder . |
java.lang.String |
toJson(JsonWriterSettings settings)
Gets a JSON representation of this document using the given
JsonWriterSettings . |
java.lang.String |
toString() |
java.util.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
public BsonDocument(java.util.List<BsonElement> bsonElements)
BsonElement
, none of which may be null.bsonElements
- a list of BsonElement
public BsonDocument(java.lang.String key, BsonValue value)
key
- the keyvalue
- the valuepublic BsonDocument()
public static BsonDocument parse(java.lang.String json)
BsonDocument
json
- the JSON stringBsonDocument
objectJsonReader
public <C> BsonDocument toBsonDocument(java.lang.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 int size()
size
in interface java.util.Map<java.lang.String,BsonValue>
public boolean isEmpty()
isEmpty
in interface java.util.Map<java.lang.String,BsonValue>
public boolean containsKey(java.lang.Object key)
containsKey
in interface java.util.Map<java.lang.String,BsonValue>
public boolean containsValue(java.lang.Object value)
containsValue
in interface java.util.Map<java.lang.String,BsonValue>
public BsonValue get(java.lang.Object key)
get
in interface java.util.Map<java.lang.String,BsonValue>
public BsonDocument getDocument(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not a BsonDocumentpublic BsonArray getArray(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonNumber getNumber(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonInt32 getInt32(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonInt64 getInt64(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDecimal128 getDecimal128(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDouble getDouble(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonBoolean getBoolean(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonString getString(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonDateTime getDateTime(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonTimestamp getTimestamp(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonObjectId getObjectId(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonRegularExpression getRegularExpression(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic BsonBinary getBinary(java.lang.Object key)
key
- the keyBsonInvalidOperationException
- if the document does not contain the key or the value is not of the expected typepublic boolean isNull(java.lang.Object key)
key
- the keypublic boolean isDocument(java.lang.Object key)
key
- the keypublic boolean isArray(java.lang.Object key)
key
- the keypublic boolean isNumber(java.lang.Object key)
key
- the keypublic boolean isInt32(java.lang.Object key)
key
- the keypublic boolean isInt64(java.lang.Object key)
key
- the keypublic boolean isDecimal128(java.lang.Object key)
key
- the keypublic boolean isDouble(java.lang.Object key)
key
- the keypublic boolean isBoolean(java.lang.Object key)
key
- the keypublic boolean isString(java.lang.Object key)
key
- the keypublic boolean isDateTime(java.lang.Object key)
key
- the keypublic boolean isTimestamp(java.lang.Object key)
key
- the keypublic boolean isObjectId(java.lang.Object key)
key
- the keypublic boolean isBinary(java.lang.Object key)
key
- the keypublic BsonValue get(java.lang.Object key, BsonValue defaultValue)
key
- the keydefaultValue
- the default valuepublic BsonDocument getDocument(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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(java.lang.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 BsonValue put(java.lang.String key, BsonValue value)
put
in interface java.util.Map<java.lang.String,BsonValue>
public BsonValue remove(java.lang.Object key)
remove
in interface java.util.Map<java.lang.String,BsonValue>
public void putAll(java.util.Map<? extends java.lang.String,? extends BsonValue> m)
putAll
in interface java.util.Map<java.lang.String,BsonValue>
public void clear()
clear
in interface java.util.Map<java.lang.String,BsonValue>
public java.util.Set<java.lang.String> keySet()
keySet
in interface java.util.Map<java.lang.String,BsonValue>
public java.util.Collection<BsonValue> values()
values
in interface java.util.Map<java.lang.String,BsonValue>
public java.util.Set<java.util.Map.Entry<java.lang.String,BsonValue>> entrySet()
entrySet
in interface java.util.Map<java.lang.String,BsonValue>
public BsonDocument append(java.lang.String key, BsonValue value)
key
- the keyvalue
- the valuepublic java.lang.String getFirstKey()
java.util.NoSuchElementException
- if the document is emptypublic boolean equals(java.lang.Object o)
equals
in interface java.util.Map<java.lang.String,BsonValue>
equals
in class java.lang.Object
public int hashCode()
hashCode
in interface java.util.Map<java.lang.String,BsonValue>
hashCode
in class java.lang.Object
public java.lang.String toJson()
JsonMode.STRICT
output mode, and otherwise the default
settings of JsonWriterSettings.Builder
.toJson(JsonWriterSettings)
,
JsonWriterSettings
public java.lang.String toJson(JsonWriterSettings settings)
JsonWriterSettings
.settings
- the JSON writer settingspublic java.lang.String toString()
toString
in class java.lang.Object
public BsonDocument clone()
clone
in class java.lang.Object