public class MongoCollectionImpl<T> extends java.lang.Object implements MongoCollection<T>
| Constructor and Description |
|---|
MongoCollectionImpl(java.lang.String collectionName,
java.util.function.Function<T,io.vertx.core.json.JsonObject> encode,
java.util.function.Function<io.vertx.core.json.JsonObject,T> decode,
MongoDataSource mds)
Important: When implementing the transformations, check that you use the key "_id" for the id.
|
| Modifier and Type | Method and Description |
|---|---|
MongoCollectionImpl<T> |
bulkInsert(java.util.Collection<T> resources,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
Inserts many resources into the collection.
|
MongoCollectionImpl<T> |
count(io.vertx.core.json.JsonObject query,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
Count matching entries in a collection.
|
MongoCollectionImpl<T> |
countAll(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
Count all entries in a collection.
|
MongoCollection<T> |
createIndex(Index index,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
Creates an index.
|
MongoCollection<T> |
deleteIndex(java.lang.String name,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
Deletes an index.
|
MongoCollectionImpl<T> |
drop(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
Drop the collection.
|
MongoCollectionImpl<T> |
find(io.vertx.core.json.JsonObject query,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<T>>> resultHandler)
Finds matching entries in a collection.
|
MongoCollectionImpl<T> |
findAll(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<T>>> resultHandler)
Finds all entries in a collection.
|
java.lang.String |
getCollectionName() |
MongoCollection<T> |
listIndexes(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<Index>>> resultHandler)
List all indexes.
|
MongoCollectionImpl<T> |
remove(io.vertx.core.json.JsonObject query,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
Remove matching entries in a collection.
|
MongoCollectionImpl<T> |
remove(java.lang.String id,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
Removes the resource with the passed ID from the collection.
|
MongoCollectionImpl<T> |
upsert(T resource,
io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> resultHandler)
Insert or update a resource into the collection.
|
public MongoCollectionImpl(java.lang.String collectionName,
java.util.function.Function<T,io.vertx.core.json.JsonObject> encode,
java.util.function.Function<io.vertx.core.json.JsonObject,T> decode,
MongoDataSource mds)
Example:
{
JsonObject encoded = new JsonObject();
encoded.put("_id", resource.getId());
encoded.put("image", new JsonObject().put("$binary", resource.getImageBytes()));
}
collectionName - The name of the collection in the database.encode - A method to transform the resource object into a JsonObject which can be handled by the database.decode - A method to transform the JsonObject return from the database into a resource object.mds - A MongoDataSource which is used to talk with the Mongo database.public java.lang.String getCollectionName()
getCollectionName in interface MongoCollection<T>public MongoCollectionImpl<T> countAll(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
MongoCollectioncountAll in interface MongoCollection<T>resultHandler - A handler to handle the AsnycResult which contains the number of all entries.public MongoCollectionImpl<T> count(io.vertx.core.json.JsonObject query, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
MongoCollectioncount in interface MongoCollection<T>query - A filter for the count request. For counting all entries in a collection use
MongoCollection.countAll(Handler).resultHandler - A handler to handle the AsnycResult which contains the number of matching entries.public MongoCollectionImpl<T> bulkInsert(java.util.Collection<T> resources, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
MongoCollectionbulkInsert in interface MongoCollection<T>resources - A collection of resources to insert into the collection.resultHandler - A handler to handle the AsnycResult which contains the number of inserted resources.public MongoCollectionImpl<T> upsert(T resource, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.String>> resultHandler)
MongoCollectionupsert in interface MongoCollection<T>resource - The resource to insert or update.resultHandler - A handler to handle the AsnycResult which contains a String with the new id (insert), or
null (update).public MongoCollectionImpl<T> findAll(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<T>>> resultHandler)
MongoCollectionfindAll in interface MongoCollection<T>resultHandler - A handler to handle the AsnycResult which contains a List with all entries.public MongoCollectionImpl<T> find(io.vertx.core.json.JsonObject query, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<T>>> resultHandler)
MongoCollectionfind in interface MongoCollection<T>query - A filter for the find request. For finding all entries in a collection use
MongoCollection.findAll(Handler).resultHandler - A handler to handle the AsnycResult which contains a List with all matching entries.public MongoCollectionImpl<T> remove(io.vertx.core.json.JsonObject query, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
MongoCollectionremove in interface MongoCollection<T>query - A filter for the remove request.resultHandler - A handler to handle the AsnycResult which contains the number of deleted entries.public MongoCollectionImpl<T> remove(java.lang.String id, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Long>> resultHandler)
MongoCollectionremove in interface MongoCollection<T>id - The ID of the resource to delete.resultHandler - A handler to handle the AsnycResult which contains the number of deleted entries.public MongoCollectionImpl<T> drop(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
MongoCollectiondrop in interface MongoCollection<T>resultHandler - A handler which will be called when complete.public MongoCollection<T> listIndexes(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.util.List<Index>>> resultHandler)
MongoCollectionlistIndexes in interface MongoCollection<T>resultHandler - A handler which contains a list of indexes.public MongoCollection<T> createIndex(Index index, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
MongoCollectioncreateIndex in interface MongoCollection<T>index - An Index object, that represents the index.resultHandler - A handler which will be called when the index is created.public MongoCollection<T> deleteIndex(java.lang.String name, io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> resultHandler)
MongoCollectiondeleteIndex in interface MongoCollection<T>name - The name of the index which should be deleted.resultHandler - A handler which will be called when the index is deleted.