public class BasicDBObject extends BasicBSONObject implements DBObject, Bson
DBObject
can be created as follows, using this class:
DBObject obj = new BasicDBObject(); obj.put( "foo", "bar" );
Constructor and Description |
---|
BasicDBObject()
Creates an empty object.
|
BasicDBObject(int size)
Creates an empty object
|
BasicDBObject(java.util.Map map)
Creates an object from a map.
|
BasicDBObject(java.lang.String key,
java.lang.Object value)
Creates an object with the given key/value
|
Modifier and Type | Method and Description |
---|---|
BasicDBObject |
append(java.lang.String key,
java.lang.Object val)
Add a key/value pair to this object
|
java.lang.Object |
copy()
Creates a new instance which is a copy of this BasicDBObject.
|
boolean |
equals(java.lang.Object o)
Compares two documents according to their serialized form, ignoring the order of keys.
|
int |
hashCode() |
boolean |
isPartialObject()
Whether
markAsPartialObject() was ever called only matters if you are going to upsert and do not want to risk losing fields. |
void |
markAsPartialObject()
If this object was retrieved with only some fields (using a field filter) this method will be called to mark it as such.
|
static BasicDBObject |
parse(java.lang.String json)
Parses a string in MongoDB Extended JSON format to a
BasicDBObject . |
static BasicDBObject |
parse(java.lang.String json,
Decoder<BasicDBObject> decoder)
Parses a string in MongoDB Extended JSON format to a
BasicDBObject . |
<TDocument> |
toBsonDocument(java.lang.Class<TDocument> 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 and DBObjectCodec . |
java.lang.String |
toJson(Encoder<BasicDBObject> encoder)
Gets a JSON representation of this document
|
java.lang.String |
toJson(JsonWriterSettings writerSettings)
Gets a JSON representation of this document
|
java.lang.String |
toJson(JsonWriterSettings writerSettings,
Encoder<BasicDBObject> encoder)
Gets a JSON representation of this document
|
java.lang.String |
toString()
Returns a JSON serialization of this object
|
containsField, containsKey, get, getBoolean, getBoolean, getDate, getDate, getDouble, getDouble, getInt, getInt, getLong, getLong, getObjectId, getObjectId, getString, getString, putAll, putAll, removeField, toMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, replaceAll, values
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putIfAbsent, remove, remove, replace, replace, size
containsField, containsKey, get, keySet, put, putAll, putAll, removeField, toMap
public BasicDBObject()
public BasicDBObject(int size)
size
- an estimate of number of fields that will be insertedpublic BasicDBObject(java.lang.String key, java.lang.Object value)
key
- key under which to storevalue
- value to storepublic BasicDBObject(java.util.Map map)
map
- map to convertpublic static BasicDBObject parse(java.lang.String json)
BasicDBObject
.json
- the JSON stringBasicDBObject
objectJsonReader
public static BasicDBObject parse(java.lang.String json, Decoder<BasicDBObject> decoder)
BasicDBObject
.json
- the JSON stringdecoder
- the decoder to use to decode the BasicDBObject instanceBasicDBObject
objectJsonReader
public BasicDBObject append(java.lang.String key, java.lang.Object val)
append
in class BasicBSONObject
key
- the field nameval
- the field valuepublic boolean isPartialObject()
markAsPartialObject()
was ever called only matters if you are going to upsert and do not want to risk losing fields.isPartialObject
in interface DBObject
public java.lang.String toJson()
JsonMode.STRICT
output mode, and otherwise the default
settings of JsonWriterSettings.Builder
and DBObjectCodec
.CodecConfigurationException
- if the document contains types not in the default registrytoJson(JsonWriterSettings)
,
JsonWriterSettings
public java.lang.String toJson(JsonWriterSettings writerSettings)
With the default DBObjectCodec
.
writerSettings
- the json writer settings to use when encodingCodecConfigurationException
- if the document contains types not in the default registrypublic java.lang.String toJson(Encoder<BasicDBObject> encoder)
With the default JsonWriterSettings
.
encoder
- the BasicDBObject codec instance to encode the document withCodecConfigurationException
- if the registry does not contain a codec for the document values.public java.lang.String toJson(JsonWriterSettings writerSettings, Encoder<BasicDBObject> encoder)
writerSettings
- the json writer settings to use when encodingencoder
- the BasicDBObject codec instance to encode the document withCodecConfigurationException
- if the registry does not contain a codec for the document values.public boolean equals(java.lang.Object o)
BasicBSONObject
equals
in interface java.util.Map<java.lang.String,java.lang.Object>
equals
in class BasicBSONObject
o
- the document to compare to, which must be an instance of BSONObject
.public int hashCode()
hashCode
in interface java.util.Map<java.lang.String,java.lang.Object>
hashCode
in class BasicBSONObject
public java.lang.String toString()
Returns a JSON serialization of this object
The output will look like: {"a":1, "b":["x","y","z"]}
toString
in class java.util.AbstractMap<java.lang.String,java.lang.Object>
public void markAsPartialObject()
markAsPartialObject
in interface DBObject
public java.lang.Object copy()
public <TDocument> BsonDocument toBsonDocument(java.lang.Class<TDocument> documentClass, CodecRegistry codecRegistry)
Bson
toBsonDocument
in interface Bson
TDocument
- 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.Copyright © 2010 - 2020 Adobe. All Rights Reserved