public final class MongoDB extends Object
Modifier and Type | Field and Description |
---|---|
static String |
_ID
It's name of object id set in Map/Object array.
|
static String |
ID
Property name of id.
|
Constructor and Description |
---|
MongoDB(com.mongodb.client.MongoDatabase mongoDB)
Instantiates a new mongo DB.
|
MongoDB(com.mongodb.client.MongoDatabase mongoDB,
com.landawn.abacus.util.AsyncExecutor asyncExecutor)
Instantiates a new mongo DB.
|
Modifier and Type | Method and Description |
---|---|
<T> com.mongodb.client.MongoCollection<T> |
collection(Class<T> targetClass,
String collectionName)
Collection.
|
com.mongodb.client.MongoCollection<org.bson.Document> |
collection(String collectionName)
Collection.
|
MongoCollectionExecutor |
collExecutor(String collectionName)
Coll executor.
|
<T> MongoCollectionMapper<T> |
collMapper(Class<T> targetClass)
Coll mapper.
|
<T> MongoCollectionMapper<T> |
collMapper(Class<T> targetClass,
String collectionName)
Coll mapper.
|
com.mongodb.client.MongoDatabase |
db()
Db.
|
static com.landawn.abacus.DataSet |
extractData(Class<?> targetClass,
com.mongodb.client.MongoIterable<?> findIterable)
Extract data.
|
static com.landawn.abacus.DataSet |
extractData(com.mongodb.client.MongoIterable<?> findIterable)
Extract data.
|
static <T> T |
fromJSON(Class<T> targetClass,
String json)
Returns an instance of the specified target class with the property values from the specified JSON String.
|
static void |
registerIdProeprty(Class<?> cls,
String idPropertyName)
The object id ("_id") property will be read from/write to the specified property .
|
static org.bson.conversions.Bson |
toBson(Object... a)
Create a new document with specified parameter(s).
|
static org.bson.conversions.Bson |
toBson(Object obj)
To bson.
|
static org.bson.BasicBSONObject |
toBSONObject(Object... a)
To BSON object.
|
static org.bson.BasicBSONObject |
toBSONObject(Object obj)
To BSON object.
|
static com.mongodb.BasicDBObject |
toDBObject(Object... a)
To DB object.
|
static com.mongodb.BasicDBObject |
toDBObject(Object obj)
To DB object.
|
static org.bson.Document |
toDocument(Object... a)
Create a new document with specified parameter(s).
|
static org.bson.Document |
toDocument(Object obj)
To document.
|
static <T> T |
toEntity(Class<T> targetClass,
org.bson.Document doc)
The id in the specified
doc will be set to the returned object if and only if the id is not null or empty and it's acceptable to the targetClass . |
static String |
toJSON(com.mongodb.BasicDBObject bsonObject)
To JSON.
|
static String |
toJSON(org.bson.conversions.Bson bson)
To JSON.
|
static String |
toJSON(org.bson.BSONObject bsonObject)
To JSON.
|
static <T> List<T> |
toList(Class<T> targetClass,
com.mongodb.client.MongoIterable<?> findIterable)
To list.
|
public static final String _ID
public static final String ID
public MongoDB(com.mongodb.client.MongoDatabase mongoDB)
mongoDB
- the mongo DBpublic MongoDB(com.mongodb.client.MongoDatabase mongoDB, com.landawn.abacus.util.AsyncExecutor asyncExecutor)
mongoDB
- the mongo DBasyncExecutor
- the async executorpublic com.mongodb.client.MongoDatabase db()
public com.mongodb.client.MongoCollection<org.bson.Document> collection(String collectionName)
collectionName
- the collection namepublic <T> com.mongodb.client.MongoCollection<T> collection(Class<T> targetClass, String collectionName)
T
- the generic typetargetClass
- the target classcollectionName
- the collection namepublic MongoCollectionExecutor collExecutor(String collectionName)
collectionName
- the collection namepublic <T> MongoCollectionMapper<T> collMapper(Class<T> targetClass)
T
- the generic typetargetClass
- the target classpublic <T> MongoCollectionMapper<T> collMapper(Class<T> targetClass, String collectionName)
T
- the generic typetargetClass
- the target classcollectionName
- the collection namepublic static void registerIdProeprty(Class<?> cls, String idPropertyName)
cls
- the clsidPropertyName
- the id property namepublic static com.landawn.abacus.DataSet extractData(com.mongodb.client.MongoIterable<?> findIterable)
findIterable
- the find iterablepublic static com.landawn.abacus.DataSet extractData(Class<?> targetClass, com.mongodb.client.MongoIterable<?> findIterable)
targetClass
- an entity class with getter/setter method or Map.class/Document.class
findIterable
- the find iterablepublic static <T> List<T> toList(Class<T> targetClass, com.mongodb.client.MongoIterable<?> findIterable)
T
- the generic typetargetClass
- an entity class with getter/setter method, Map.class
or basic single value type(Primitive/String/Date...)findIterable
- the find iterablepublic static <T> T toEntity(Class<T> targetClass, org.bson.Document doc)
doc
will be set to the returned object if and only if the id is not null or empty and it's acceptable to the targetClass
.T
- the generic typetargetClass
- an entity class with getter/setter method, or Map.class
.doc
- the docpublic static String toJSON(org.bson.conversions.Bson bson)
bson
- the bsonpublic static String toJSON(org.bson.BSONObject bsonObject)
bsonObject
- the bson objectpublic static String toJSON(com.mongodb.BasicDBObject bsonObject)
bsonObject
- the bson objectpublic static <T> T fromJSON(Class<T> targetClass, String json)
T
- the generic typetargetClass
- Bson.class
, Document.class
, BasicBSONObject.class
, BasicDBObject.class
json
- the jsonpublic static org.bson.conversions.Bson toBson(Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.conversions.Bson toBson(Object... a)
a
- the apublic static org.bson.Document toDocument(Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.Document toDocument(Object... a)
a
- the apublic static org.bson.BasicBSONObject toBSONObject(Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.BasicBSONObject toBSONObject(Object... a)
a
- the apublic static com.mongodb.BasicDBObject toDBObject(Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static com.mongodb.BasicDBObject toDBObject(Object... a)
a
- the aCopyright © 2019. All rights reserved.