public final class MongoDB
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
_ID
It's name of object id set in Map/Object array.
|
static java.lang.String |
ID
Property name of id.
|
Constructor and Description |
---|
MongoDB(com.mongodb.client.MongoDatabase mongoDB) |
MongoDB(com.mongodb.client.MongoDatabase mongoDB,
AsyncExecutor asyncExecutor) |
Modifier and Type | Method and Description |
---|---|
<T> com.mongodb.client.MongoCollection<T> |
collection(java.lang.Class<T> targetClass,
java.lang.String collectionName) |
com.mongodb.client.MongoCollection<org.bson.Document> |
collection(java.lang.String collectionName) |
MongoCollectionExecutor |
collExecutor(java.lang.String collectionName) |
<T> MongoCollectionMapper<T> |
collMapper(java.lang.Class<T> targetClass) |
<T> MongoCollectionMapper<T> |
collMapper(java.lang.Class<T> targetClass,
java.lang.String collectionName) |
com.mongodb.client.MongoDatabase |
db() |
static DataSet |
extractData(java.lang.Class<?> targetClass,
com.mongodb.client.MongoIterable<?> findIterable) |
static DataSet |
extractData(com.mongodb.client.MongoIterable<?> findIterable) |
static <T> T |
fromJSON(java.lang.Class<T> targetClass,
java.lang.String json)
Returns an instance of the specified target class with the property values from the specified JSON String.
|
static void |
registerIdProeprty(java.lang.Class<?> cls,
java.lang.String idPropertyName)
The object id ("_id") property will be read from/write to the specified property
|
static org.bson.conversions.Bson |
toBson(java.lang.Object... a)
Create a new document with specified parameter(s).
|
static org.bson.conversions.Bson |
toBson(java.lang.Object obj) |
static org.bson.BasicBSONObject |
toBSONObject(java.lang.Object... a) |
static org.bson.BasicBSONObject |
toBSONObject(java.lang.Object obj) |
static com.mongodb.BasicDBObject |
toDBObject(java.lang.Object... a) |
static com.mongodb.BasicDBObject |
toDBObject(java.lang.Object obj) |
static org.bson.Document |
toDocument(java.lang.Object... a)
Create a new document with specified parameter(s).
|
static org.bson.Document |
toDocument(java.lang.Object obj) |
static <T> T |
toEntity(java.lang.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 java.lang.String |
toJSON(com.mongodb.BasicDBObject bsonObject) |
static java.lang.String |
toJSON(org.bson.conversions.Bson bson) |
static java.lang.String |
toJSON(org.bson.BSONObject bsonObject) |
static <T> java.util.List<T> |
toList(java.lang.Class<T> targetClass,
com.mongodb.client.MongoIterable<?> findIterable) |
public static final java.lang.String _ID
public static final java.lang.String ID
public MongoDB(com.mongodb.client.MongoDatabase mongoDB)
public MongoDB(com.mongodb.client.MongoDatabase mongoDB, AsyncExecutor asyncExecutor)
public com.mongodb.client.MongoDatabase db()
public com.mongodb.client.MongoCollection<org.bson.Document> collection(java.lang.String collectionName)
public <T> com.mongodb.client.MongoCollection<T> collection(java.lang.Class<T> targetClass, java.lang.String collectionName)
public MongoCollectionExecutor collExecutor(java.lang.String collectionName)
public <T> MongoCollectionMapper<T> collMapper(java.lang.Class<T> targetClass)
public <T> MongoCollectionMapper<T> collMapper(java.lang.Class<T> targetClass, java.lang.String collectionName)
public static void registerIdProeprty(java.lang.Class<?> cls, java.lang.String idPropertyName)
cls
- idPropertyName
- public static DataSet extractData(com.mongodb.client.MongoIterable<?> findIterable)
public static DataSet extractData(java.lang.Class<?> targetClass, com.mongodb.client.MongoIterable<?> findIterable)
targetClass
- an entity class with getter/setter method or Map.class/Document.class
findIterable
- public static <T> java.util.List<T> toList(java.lang.Class<T> targetClass, com.mongodb.client.MongoIterable<?> findIterable)
targetClass
- an entity class with getter/setter method, Map.class
or basic single value type(Primitive/String/Date...)findIterable
- public static <T> T toEntity(java.lang.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
.targetClass
- an entity class with getter/setter method, or Map.class
.doc
- public static java.lang.String toJSON(org.bson.conversions.Bson bson)
public static java.lang.String toJSON(org.bson.BSONObject bsonObject)
public static java.lang.String toJSON(com.mongodb.BasicDBObject bsonObject)
public static <T> T fromJSON(java.lang.Class<T> targetClass, java.lang.String json)
targetClass
- Bson.class
, Document.class
, BasicBSONObject.class
, BasicDBObject.class
json
- public static org.bson.conversions.Bson toBson(java.lang.Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.conversions.Bson toBson(java.lang.Object... a)
a
- public static org.bson.Document toDocument(java.lang.Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.Document toDocument(java.lang.Object... a)
a
- public static org.bson.BasicBSONObject toBSONObject(java.lang.Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static org.bson.BasicBSONObject toBSONObject(java.lang.Object... a)
public static com.mongodb.BasicDBObject toDBObject(java.lang.Object obj)
obj
- an array of pairs of property name and value/Map@SafeVarargs public static com.mongodb.BasicDBObject toDBObject(java.lang.Object... a)