public class Document extends java.lang.Object implements java.util.Map<java.lang.String,java.lang.Object>, java.io.Serializable, Bson
Map. All iterators will traverse the elements in insertion order, as with LinkedHashMap.| 构造器和说明 |
|---|
Document()
Creates an empty Document instance.
|
Document(java.util.Map<java.lang.String,java.lang.Object> map)
Creates a Document instance initialized with the given map.
|
Document(java.lang.String key,
java.lang.Object value)
Create a Document instance initialized with the given key/value pair.
|
| 限定符和类型 | 方法和说明 |
|---|---|
Document |
append(java.lang.String key,
java.lang.Object value)
Put the given key/value pair into this Document and return this.
|
void |
clear() |
boolean |
containsKey(java.lang.Object key) |
boolean |
containsValue(java.lang.Object value) |
java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> |
entrySet() |
boolean |
equals(java.lang.Object o) |
java.lang.Object |
get(java.lang.Object key) |
<T> T |
get(java.lang.Object key,
java.lang.Class<T> clazz)
Gets the value of the given key, casting it to the given
Class<T>. |
java.lang.Boolean |
getBoolean(java.lang.Object key)
Gets the value of the given key as a Boolean.
|
boolean |
getBoolean(java.lang.Object key,
boolean defaultValue)
Gets the value of the given key as a primitive boolean.
|
java.util.Date |
getDate(java.lang.Object key)
Gets the value of the given key as a Date.
|
java.lang.Double |
getDouble(java.lang.Object key)
Gets the value of the given key as a Double.
|
java.lang.Integer |
getInteger(java.lang.Object key)
Gets the value of the given key as an Integer.
|
int |
getInteger(java.lang.Object key,
int defaultValue)
Gets the value of the given key as a primitive int.
|
java.lang.Long |
getLong(java.lang.Object key)
Gets the value of the given key as a Long.
|
ObjectId |
getObjectId(java.lang.Object key)
Gets the value of the given key as an ObjectId.
|
java.lang.String |
getString(java.lang.Object key)
Gets the value of the given key as a String.
|
int |
hashCode() |
boolean |
isEmpty() |
java.util.Set<java.lang.String> |
keySet() |
static Document |
parse(java.lang.String json)
Parses a string in MongoDB Extended JSON format to a
Document |
static Document |
parse(java.lang.String json,
Decoder<Document> decoder)
Parses a string in MongoDB Extended JSON format to a
Document |
java.lang.Object |
put(java.lang.String key,
java.lang.Object value) |
void |
putAll(java.util.Map<? extends java.lang.String,?> map) |
java.lang.Object |
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
With the default
JsonWriterSettings and DocumentCodec. |
java.lang.String |
toJson(Encoder<Document> encoder)
Gets a JSON representation of this document
With the default
JsonWriterSettings. |
java.lang.String |
toJson(JsonWriterSettings writerSettings)
Gets a JSON representation of this document
With the default
DocumentCodec. |
java.lang.String |
toJson(JsonWriterSettings writerSettings,
Encoder<Document> encoder)
Gets a JSON representation of this document
|
java.lang.String |
toString() |
java.util.Collection<java.lang.Object> |
values() |
public Document()
public Document(java.lang.String key,
java.lang.Object value)
key - keyvalue - valuepublic Document(java.util.Map<java.lang.String,java.lang.Object> map)
map - initial mappublic static Document parse(java.lang.String json)
Documentjson - the JSON stringDocument objectJsonReaderpublic static Document parse(java.lang.String json, Decoder<Document> decoder)
Documentjson - the JSON stringdecoder - the Decoder to use to parse the JSON string into a DocumentDocument objectJsonReaderpublic <C> BsonDocument toBsonDocument(java.lang.Class<C> documentClass, CodecRegistry codecRegistry)
BsontoBsonDocument 在接口中 BsonC - 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 Document append(java.lang.String key, java.lang.Object value)
doc.append("a", 1).append("b", 2)}
key - keyvalue - valuepublic <T> T get(java.lang.Object key,
java.lang.Class<T> clazz)
Class<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 write String name =
doc.get("name", String.class) instead of String name = (String) doc.get("x") .T - the type of the classkey - the keyclazz - the non-null class to cast the value tojava.lang.ClassCastException - if the value of the given key is not of type Tpublic java.lang.Integer getInteger(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not an integerpublic int getInteger(java.lang.Object key,
int defaultValue)
key - the keydefaultValue - what to return if the value is nulljava.lang.ClassCastException - if the value is not an integerpublic java.lang.Long getLong(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not an longpublic java.lang.Double getDouble(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not an doublepublic java.lang.String getString(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not a Stringpublic java.lang.Boolean getBoolean(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not an doublepublic boolean getBoolean(java.lang.Object key,
boolean defaultValue)
key - the keydefaultValue - what to return if the value is nulljava.lang.ClassCastException - if the value is not an doublepublic ObjectId getObjectId(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not an ObjectIdpublic java.util.Date getDate(java.lang.Object key)
key - the keyjava.lang.ClassCastException - if the value is not a Datepublic java.lang.String toJson()
With the default JsonWriterSettings and DocumentCodec.
CodecConfigurationException - if the document contains types not in the default registrypublic java.lang.String toJson(JsonWriterSettings writerSettings)
With the default DocumentCodec.
writerSettings - the json writer settings to use when encodingCodecConfigurationException - if the document contains types not in the default registrypublic java.lang.String toJson(Encoder<Document> encoder)
With the default JsonWriterSettings.
encoder - the document codec instance to use to encode the documentCodecConfigurationException - if the registry does not contain a codec for the document values.public java.lang.String toJson(JsonWriterSettings writerSettings, Encoder<Document> encoder)
writerSettings - the json writer settings to use when encodingencoder - the document codec instance to use to encode the documentCodecConfigurationException - if the registry does not contain a codec for the document values.public int size()
size 在接口中 java.util.Map<java.lang.String,java.lang.Object>public boolean isEmpty()
isEmpty 在接口中 java.util.Map<java.lang.String,java.lang.Object>public boolean containsValue(java.lang.Object value)
containsValue 在接口中 java.util.Map<java.lang.String,java.lang.Object>public boolean containsKey(java.lang.Object key)
containsKey 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object get(java.lang.Object key)
get 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object put(java.lang.String key,
java.lang.Object value)
put 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.lang.Object remove(java.lang.Object key)
remove 在接口中 java.util.Map<java.lang.String,java.lang.Object>public void putAll(java.util.Map<? extends java.lang.String,?> map)
putAll 在接口中 java.util.Map<java.lang.String,java.lang.Object>public void clear()
clear 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.util.Set<java.lang.String> keySet()
keySet 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.util.Collection<java.lang.Object> values()
values 在接口中 java.util.Map<java.lang.String,java.lang.Object>public java.util.Set<java.util.Map.Entry<java.lang.String,java.lang.Object>> entrySet()
entrySet 在接口中 java.util.Map<java.lang.String,java.lang.Object>public boolean equals(java.lang.Object o)
equals 在接口中 java.util.Map<java.lang.String,java.lang.Object>equals 在类中 java.lang.Objectpublic int hashCode()
hashCode 在接口中 java.util.Map<java.lang.String,java.lang.Object>hashCode 在类中 java.lang.Objectpublic java.lang.String toString()
toString 在类中 java.lang.Object