Class MongoDAO
java.lang.Object
services.moleculer.mongo.MongoFilters
services.moleculer.mongo.MongoDAO
- Direct Known Subclasses:
SpringMongoDAO
Superclass of all Mongo handlers. If it used with Spring Framework, the DAO
classes must be annotated with the @Repository or @Component annotation.
Sample DAO class for handling "User" entities:
@MongoCollection("user")
public class UserDAO extends MongoDAO {
public Promise insertUser(String firstName, String lastName) {
Tree doc = new Tree();
doc.put("firstName", firstName);
doc.put("lastName", lastName);
return insertOne(doc).then(res -> {
return res.get("_id", "");
});
}
public Promise findUserById(String id) {
return findOne(eq(id));
}
public Promise deleteUserById(String id) {
return deleteOne(eq(id)).then(res -> {
return res.get("deleted", 0) > 0;
});
}
}
Example of using the code above:
userDAO.insertUser("Tom", "Smith").then(res -> {
System.out.println("Record ID: " + res.asString());
});
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected io.datatree.Promisecount()Counts the number of documents in the collection.protected io.datatree.Promisecount(io.datatree.Tree filter) Counts the number of documents in the collection according to the given filters.protected io.datatree.Promisecount(io.datatree.Tree filter, com.mongodb.client.model.CountOptions options) Counts the number of documents in the collection according to the given options.protected io.datatree.PromisecreateAscendingIndexes(String... fieldNames) Creates ascending indexes.protected io.datatree.PromisecreateDescendingIndexes(String... fieldNames) Creates descending indexes.protected io.datatree.PromisecreateGeo2DIndex(String fieldName) Creates a geo2d index.protected io.datatree.PromisecreateGeo2DSphereIndexes(String... fieldNames) Creates 2dsphere indexes.protected io.datatree.PromisecreateHashedIndex(String fieldName) Creates a hashed index.protected io.datatree.PromisecreateIndexes(io.datatree.Tree indexes) Creates an index by the specified Tree object.protected io.datatree.PromisecreateIndexes(org.bson.conversions.Bson key) Creates an index by the specified Bson object.protected io.datatree.PromisecreateTextIndex(String fieldName) Creates a text index.protected io.datatree.PromiseRemoves all documents from the collection.
Sample to delete result structure:protected io.datatree.PromisedeleteMany(io.datatree.Tree filter) Removes all documents from the collection that match the given query filter.protected io.datatree.PromisedeleteMany(io.datatree.Tree filter, com.mongodb.client.model.DeleteOptions options) Removes all documents from the collection that match the given query filter.protected io.datatree.PromisedeleteOne(io.datatree.Tree filter) Removes at most one document from the collection that matches the given filter.protected io.datatree.PromisedeleteOne(io.datatree.Tree filter, com.mongodb.client.model.DeleteOptions options) Removes at most one document from the collection that matches the given filter.protected io.datatree.Promisedrop()Drops this collection from the Database.protected io.datatree.PromiseDrops the specified index.protected io.datatree.PromiseDrops the given index.protected io.datatree.Promisefind(io.datatree.Tree filter) Queries the all records from the collection by the specified filter.protected io.datatree.Promisefind(io.datatree.Tree filter, io.datatree.Tree sort) Queries the all records from the collection by the specified filter.protected io.datatree.Promisefind(io.datatree.Tree filter, io.datatree.Tree sort, int first, int limit) Queries the specified number of records from the collection.protected io.datatree.PromisefindOne(io.datatree.Tree filter) Finds one document by the specified query filter.protected io.datatree.PromisefindOneAndDelete(io.datatree.Tree filter) Atomically find a document and remove it.protected io.datatree.PromisefindOneAndDelete(io.datatree.Tree filter, com.mongodb.client.model.FindOneAndDeleteOptions options) Atomically find a document and remove it.protected io.datatree.PromisefindOneAndReplace(io.datatree.Tree filter, io.datatree.Tree replacement) Atomically find a document and replace it.protected io.datatree.PromisefindOneAndReplace(io.datatree.Tree filter, io.datatree.Tree replacement, com.mongodb.client.model.FindOneAndReplaceOptions options) Atomically find a document and replace it.protected io.datatree.PromisefindOneAndUpdate(io.datatree.Tree filter, io.datatree.Tree update) Atomically find a document and update it.protected io.datatree.PromisefindOneAndUpdate(io.datatree.Tree filter, io.datatree.Tree update, com.mongodb.client.model.FindOneAndUpdateOptions options) Atomically find a document and update it.final com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> final intprotected io.datatree.PromiseinsertOne(io.datatree.Tree document) Inserts the provided document.protected io.datatree.PromiseinsertOne(io.datatree.Tree document, com.mongodb.client.model.InsertOneOptions options) Inserts the provided document.protected io.datatree.PromiseGet all the indexes in this collection.
Sample return structure:protected io.datatree.PromiseAggregates documents according to the specified map-reduce function.protected io.datatree.PromiserenameCollection(String databaseName, String collectionName) Rename the collection.protected io.datatree.PromiserenameCollection(String databaseName, String collectionName, com.mongodb.client.model.RenameCollectionOptions options) Rename the collection.protected io.datatree.PromisereplaceOne(io.datatree.Tree filter, io.datatree.Tree replacement) Replace a document in the collection according to the specified arguments.protected io.datatree.PromisereplaceOne(io.datatree.Tree filter, io.datatree.Tree replacement, com.mongodb.client.model.ReplaceOptions options) Replace a document in the collection according to the specified arguments.final voidsetCollection(com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> collection) final voidsetMaxItemsPerQuery(int maxItemsPerQuery) voidSets the MongoConnectionPool of this DAO.protected io.datatree.PromiseupdateMany(io.datatree.Tree filter, io.datatree.Tree update) Update all documents in the collection according to the specified arguments.protected io.datatree.PromiseupdateOne(io.datatree.Tree filter, io.datatree.Tree update) Update a single document in the collection according to the specified arguments.
-
Field Details
-
ROWS
- See Also:
-
COUNT
- See Also:
-
SET
- See Also:
-
ID
- See Also:
-
MATCHED
- See Also:
-
MODIFIED
- See Also:
-
DELETED
- See Also:
-
ACKNOWLEDGED
- See Also:
-
collection
protected com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> collection -
maxItemsPerQuery
protected int maxItemsPerQuery
-
-
Constructor Details
-
MongoDAO
public MongoDAO()
-
-
Method Details
-
setMongoConnectionPool
Sets the MongoConnectionPool of this DAO. Processes the @MongoCollection annotation. If no annotation is specified, generates the collection name from the Class name (eg from "UserDAO" to "user").- Parameters:
pool- the MongoConnectionPool to use
-
drop
protected io.datatree.Promise drop()Drops this collection from the Database. Sample of usage:drop().then(res -> { // Drop operation finished });- Returns:
- a Promise with a single element indicating when the operation has completed
-
renameCollection
Rename the collection. Sample of usage:renameCollection("db", "collection").then(res -> { // Rename operation finished });- Parameters:
databaseName- name of the databasecollectionName- new collection name- Returns:
- a Promise with a single element indicating when the operation has completed
-
renameCollection
protected io.datatree.Promise renameCollection(String databaseName, String collectionName, com.mongodb.client.model.RenameCollectionOptions options) Rename the collection. Sample of usage:RenameCollectionOptions opts = new RenameCollectionOptions(); opts.dropTarget(false); renameCollection("db", "collection", opts).then(res -> { // Rename operation finished });- Parameters:
databaseName- name of the databasecollectionName- new collection nameoptions- the options for renaming a collection- Returns:
- a Promise with a single element indicating when the operation has completed
-
createAscendingIndexes
Creates ascending indexes. Sample of usage:createAscendingIndexes("field1", "field2").then(res -> { // Index created successfully }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
fieldNames- field names- Returns:
- a Promise with a single element indicating when the operation has completed
-
createDescendingIndexes
Creates descending indexes. Sample of usage:createDescendingIndexes("field1", "field2").then(res -> { // Index created successfully });- Parameters:
fieldNames- field names- Returns:
- a Promise with a single element indicating when the operation has completed
-
createGeo2DSphereIndexes
Creates 2dsphere indexes. Sample of usage:createGeo2DSphereIndexes("field1", "field2").then(res -> { // Index created successfully });- Parameters:
fieldNames- field names- Returns:
- a Promise with a single element indicating when the operation has completed
-
createGeo2DIndex
Creates a geo2d index. Sample of usage:createGeo2DIndex("field1").then(res -> { // Index created successfully });- Parameters:
fieldName- field name- Returns:
- a Promise with a single element indicating when the operation has completed
-
createHashedIndex
Creates a hashed index. Sample of usage:createHashedIndex("field1").then(res -> { // Index created successfully });- Parameters:
fieldName- field name- Returns:
- a Promise with a single element indicating when the operation has completed
-
createTextIndex
Creates a text index. Sample of usage:createTextIndex("field1").then(res -> { // Index created successfully }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
fieldName- field name- Returns:
- a Promise with a single element indicating when the operation has completed
-
createIndexes
protected io.datatree.Promise createIndexes(io.datatree.Tree indexes) Creates an index by the specified Tree object. Sample of usage:BsonTree indexes = new BsonTree(Indexes.text("field1")); createIndexes(indexes).then(res -> { // Index created successfully });- Parameters:
indexes- list of fields- Returns:
- a Promise with a single element indicating when the operation has completed
-
createIndexes
protected io.datatree.Promise createIndexes(org.bson.conversions.Bson key) Creates an index by the specified Bson object. Sample of usage:createIndexes(Indexes.text("field1")).then(res -> { // Index created successfully });- Parameters:
key- an object describing the index key(s), which may not be null.- Returns:
- a Promise with a single element indicating when the operation has completed
-
listIndexes
protected io.datatree.Promise listIndexes()Get all the indexes in this collection.
Sample return structure:{ "count":2, "rows":[ { "v":1, "key":{"_id":1}, "name":"_id_", "ns":"db.test" }, { "v":1, "key":{"a":1}, "name":"a_1", "ns":"db.test" } ] }Sample of usage:listIndexes().then(res -> { // Operation finished for (Tree index : res.get("rows")) { System.out.println(index.get("name", "")); } });- Returns:
- a Promise with the list of indexes, and number of indexes
-
dropIndex
Drops the specified index. Sample of usage:dropIndex("field1").then(res -> { // Drop index operation finished }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
indexName- the name of the index to remove- Returns:
- a Promise with a single element indicating when the operation has completed
-
dropIndex
protected io.datatree.Promise dropIndex(String indexName, com.mongodb.client.model.DropIndexOptions options) Drops the given index. Sample of usage:DropIndexOptions opts = new DropIndexOptions(); opts.maxTime(10, TimeUnit.SECONDS); dropIndex("field1", opts).then(res -> { // Drop index operation finished });- Parameters:
indexName- the name of the index to removeoptions- options to use when dropping indexes- Returns:
- a Promise with a single element indicating when the operation has completed
-
insertOne
protected io.datatree.Promise insertOne(io.datatree.Tree document) Inserts the provided document. If the document is missing an identifier, the driver should generate one. Sample of usage:Tree doc = new Tree(); doc.put("field1", 123); doc.put("field2.subfield", false); insertOne(doc).then(res -> { // Insert operation finished String id = res.get("_id", ""); return id; });- Parameters:
document- the document to insert- Returns:
- a Promise with a single element indicating when the operation has completed
-
insertOne
protected io.datatree.Promise insertOne(io.datatree.Tree document, com.mongodb.client.model.InsertOneOptions options) Inserts the provided document. If the document is missing an identifier, the driver should generate one. Sample of usage:Tree doc = new Tree(); doc.put("field1", 123); InsertOneOptions opts = new InsertOneOptions(); opts.bypassDocumentValidation(false); insertOne(doc, opts).then(res -> { // Insert operation finished String id = res.get("_id", ""); return id; });- Parameters:
document- the document to insertoptions- the options to apply to the operation- Returns:
- a Promise with a single element indicating when the operation has completed
-
replaceOne
protected io.datatree.Promise replaceOne(io.datatree.Tree filter, io.datatree.Tree replacement) Replace a document in the collection according to the specified arguments.
Sample to update result structure:{ "matched": 10, "modified": 4, "acknowledged": true }Sample of usage:Tree replacement = new Tree(); replacement.put("field1", 123); replaceOne(eq("field1", 123), replacement).then(res -> { // Replace operation finished int modified = res.get("modified"); return modified > 0; }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
filter- the query filter to apply the the replace operationreplacement- the replacement document- Returns:
- a Promise with a single element the update result structure
-
replaceOne
protected io.datatree.Promise replaceOne(io.datatree.Tree filter, io.datatree.Tree replacement, com.mongodb.client.model.ReplaceOptions options) Replace a document in the collection according to the specified arguments.
Sample to update result structure:{ "matched": 10, "modified": 4, "acknowledged": true }Sample of usage:Tree replacement = new Tree(); replacement.put("field1", 123); ReplaceOptions opts = new ReplaceOptions(); opts.bypassDocumentValidation(false); replaceOne(eq("field1", 123), replacement, opts).then(res -> { // Replace operation finished int modified = res.get("modified"); return modified > 0; });- Parameters:
filter- the query filter to apply the the replace operationreplacement- the replacement documentoptions- the options to apply to the replace operation- Returns:
- a Promise with a single element the update result structure
-
updateOne
protected io.datatree.Promise updateOne(io.datatree.Tree filter, io.datatree.Tree update) Update a single document in the collection according to the specified arguments.
Sample to update result structure:{ "matched": 10, "modified": 4, "acknowledged": true }Sample of usage:Tree update = new Tree(); update.put("field1", 123); updateOne(eq("field1", 123), update).then(res -> { // Replace operation finished int modified = res.get("modified"); return modified > 0; }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
filter- a document describing the query filter, which may not be null.update- a document describing the update, which may not be null. The update to apply must include only update operators.- Returns:
- a Promise with a single element the update result structure
-
updateMany
protected io.datatree.Promise updateMany(io.datatree.Tree filter, io.datatree.Tree update) Update all documents in the collection according to the specified arguments.
Sample to update result structure:{ "matched": 10, "modified": 4, "acknowledged": true }Sample of usage:Tree update = new Tree(); update.put("field1", 123); updateMany(eq("field1", 123), update).then(res -> { // Replace operation finished int modified = res.get("modified"); return modified > 0; });- Parameters:
filter- a document describing the query filter, which may not be null.update- a document describing the update, which may not be null. The update to apply must include only update operators.- Returns:
- a Promise with a single element the update result structure
-
deleteOne
protected io.datatree.Promise deleteOne(io.datatree.Tree filter) Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.
Sample to delete result structure:{ "deleted": 4, "acknowledged": true }Sample of usage:deleteOne(eq("field1", 123)).then(res -> { // Delete operation finished int deleted = res.get("deleted"); return deleted > 0; });- Parameters:
filter- the query filter to apply the the delete operation- Returns:
- a Promise with a single element the deleted result structure
-
deleteOne
protected io.datatree.Promise deleteOne(io.datatree.Tree filter, com.mongodb.client.model.DeleteOptions options) Removes at most one document from the collection that matches the given filter. If no documents match, the collection is not modified.
Sample to delete result structure:{ "deleted": 4, "acknowledged": true }Sample of usage:DeleteOptions opts = new DeleteOptions(); opts.collation(...); deleteOne(eq("field1", 123), opts).then(res -> { // Delete operation finished int deleted = res.get("deleted"); return deleted > 0; });- Parameters:
filter- the query filter to apply the the delete operationoptions- the options to apply to the delete operation- Returns:
- a Promise with a single element the deleted result structure
-
deleteAll
protected io.datatree.Promise deleteAll()Removes all documents from the collection.
Sample to delete result structure:{ "deleted": 10, "acknowledged": true }Sample of usage:deleteAll().then(res -> { // Delete operation finished int deleted = res.get("deleted"); return deleted > 0; });- Returns:
- a Promise with a single element the deleted result structure
-
deleteMany
protected io.datatree.Promise deleteMany(io.datatree.Tree filter) Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.
Sample to delete result structure:{ "deleted": 4, "acknowledged": true }Sample of usage:deleteMany(eq("field1", 123)).then(res -> { // Delete operation finished int deleted = res.get("deleted"); return deleted > 0; });- Parameters:
filter- the query filter to apply the the delete operation- Returns:
- a Promise with a single element the deleted result structure
-
deleteMany
protected io.datatree.Promise deleteMany(io.datatree.Tree filter, com.mongodb.client.model.DeleteOptions options) Removes all documents from the collection that match the given query filter. If no documents match, the collection is not modified.
Sample to delete result structure:{ "deleted": 4, "acknowledged": true }Sample of usage:DeleteOptions opts = new DeleteOptions(); opts.collation(...); deleteMany(eq("field1", 123), opts).then(res -> { // Delete operation finished int deleted = res.get("deleted"); return deleted > 0; }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
filter- the query filter to apply the the delete operationoptions- the options to apply to the delete operation- Returns:
- a Promise with a single element the deleted result structure
-
count
protected io.datatree.Promise count()Counts the number of documents in the collection. Sample of usage:count().then(res -> { // Count operation finished long numberOfDocuments = res.asLong(); return numberOfDocuments + " documents found."; });- Returns:
- a Promise with a single element indicating the number of documents
-
count
protected io.datatree.Promise count(io.datatree.Tree filter) Counts the number of documents in the collection according to the given filters. Sample of usage:count(eq("field1", 123)).then(res -> { // Count operation finished long numberOfDocuments = res.asLong(); Tree rsp = new Tree(); rsp.put("count", numberOfDocuments); return rsp; });- Parameters:
filter- the query filter- Returns:
- a Promise with a single element indicating the number of documents
-
count
protected io.datatree.Promise count(io.datatree.Tree filter, com.mongodb.client.model.CountOptions options) Counts the number of documents in the collection according to the given options. Sample of usage:CountOptions opts = new CountOptions(); opts.maxTime(10, TimeUnit.SECONDS); count(eq("field1", 123), opts).then(res -> { // Count operation finished long numberOfDocuments = res.asLong(); Tree rsp = new Tree(); rsp.put("count", numberOfDocuments); return rsp; });- Parameters:
filter- the query filteroptions- the options describing the count- Returns:
- a Promise with a single element indicating the number of documents
-
findOne
protected io.datatree.Promise findOne(io.datatree.Tree filter) Finds one document by the specified query filter. Sample of usage:findOne(eq("field1", 123)).then(res -> { // Find operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- the query filter- Returns:
- a Promise with the selected document.
-
find
protected io.datatree.Promise find(io.datatree.Tree filter) Queries the all records from the collection by the specified filter. Sample of usage:find(gte("field1", 123), sort).then(res -> { // Find operation finished });- Parameters:
filter- the query filter- Returns:
- a Promise with the selected documents and the max number of selectable documents.
-
find
protected io.datatree.Promise find(io.datatree.Tree filter, io.datatree.Tree sort) Queries the all records from the collection by the specified filter. Sample of usage:Tree sort = new Tree(); sort.put("field1", -1); find(lt("field1", 100), sort).then(res -> { // Find operation finished });- Parameters:
filter- the query filtersort- sort filter (or null)- Returns:
- a Promise with the selected documents and the max number of selectable documents.
-
find
protected io.datatree.Promise find(io.datatree.Tree filter, io.datatree.Tree sort, int first, int limit) Queries the specified number of records from the collection. Sample of usage:Tree sort = new Tree(); sort.put("field2", 1); find(lte("field1", 123), null, 0, 10).then(res -> { // Find operation finished int maxNumberOfSelectableDocuments = res.get("count"); for (Tree doc : res.get("rows")) { String firstName = res.get("firstName", ""); } return res; }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
filter- the query filtersort- sort filter (or null)first- number of skipped documents (0 = get from the first record)limit- number of retrieved documents- Returns:
- a Promise with the selected documents and the max number of selectable documents.
-
findOneAndDelete
protected io.datatree.Promise findOneAndDelete(io.datatree.Tree filter) Atomically find a document and remove it. Sample of usage:findOneAndDelete(eq("field1", 123)).then(res -> { // Delete operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- the query filter to find the document with- Returns:
- a Promise with a single element the document that was removed. If no documents matched the query filter, then null will be returned
-
findOneAndDelete
protected io.datatree.Promise findOneAndDelete(io.datatree.Tree filter, com.mongodb.client.model.FindOneAndDeleteOptions options) Atomically find a document and remove it. Sample of usage:FindOneAndDeleteOptions opts = new FindOneAndDeleteOptions(); opts.maxTime(10, TimeUnit.SECONDS); findOneAndDelete(eq("field1", 123), opts).then(res -> { // Delete operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- the query filter to find the document withoptions- the options to apply to the operation- Returns:
- a Promise with a single element the document that was removed. If no documents matched the query filter, then null will be returned
-
findOneAndReplace
protected io.datatree.Promise findOneAndReplace(io.datatree.Tree filter, io.datatree.Tree replacement) Atomically find a document and replace it. Sample of usage:Tree replacement = new Tree(); replacement.put("field1", 222); findOneAndReplace(eq("field1", 123), replacement).then(res -> { // Replace operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- the query filter to apply the the replace operationreplacement- the replacement document- Returns:
- a Promise with a single element the document that was replaced. If no documents matched the query filter, then null will be returned
-
findOneAndReplace
protected io.datatree.Promise findOneAndReplace(io.datatree.Tree filter, io.datatree.Tree replacement, com.mongodb.client.model.FindOneAndReplaceOptions options) Atomically find a document and replace it. Sample of usage:Tree replacement = new Tree(); replacement.put("field1", 111); FindOneAndReplaceOptions opts = new FindOneAndReplaceOptions(); opts.upsert(true); findOneAndReplace(eq("field1", 123), replacement, opts).then(res -> { // Replace operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
filter- the query filter to apply the the replace operationreplacement- the replacement documentoptions- the options to apply to the operation- Returns:
- a Promise with a single element the document that was replaced. If no documents matched the query filter, then null will be returned
-
findOneAndUpdate
protected io.datatree.Promise findOneAndUpdate(io.datatree.Tree filter, io.datatree.Tree update) Atomically find a document and update it. Sample of usage:Tree update = new Tree(); update.put("field1", 345); findOneAndUpdate(eq("field1", 123), update).then(res -> { // Update operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- a document describing the query filter, which may not be null.update- a document describing the update, which may not be null. The update to apply must include only update operators.- Returns:
- a Promise with a single element the document that was updated before the update was applied. If no documents matched the query filter, then null will be returned
-
findOneAndUpdate
protected io.datatree.Promise findOneAndUpdate(io.datatree.Tree filter, io.datatree.Tree update, com.mongodb.client.model.FindOneAndUpdateOptions options) Atomically find a document and update it. Sample of usage:Tree update = new Tree(); update.put("field1", 345); FindOneAndUpdateOptions opts = new FindOneAndUpdateOptions(); opts.upsert(true); findOneAndUpdate(eq("field1", 123), update, opts).then(res -> { // Update operation finished if (res != null) { String firstName = res.get("firstName", ""); int age = res.get("age", 0); } return res; });- Parameters:
filter- a document describing the query filter, which may not be null.update- a document describing the update, which may not be null. The update to apply must include only update operators.options- the options to apply to the operation- Returns:
- a Promise with a single element the document that was updated.
-
mapReduce
Aggregates documents according to the specified map-reduce function. Sample of usage:String mapFunction = "..."; String reduceFunction = "..."; mapReduce(mapFunction, reduceFunction).then(res -> { // Operation finished }).then(res -> { // ... }).then(res -> { // ... }).catchError(err -> { // Error handler });- Parameters:
mapFunction- A JavaScript function that associates or "maps" a value with a key and emits the key and value pair.reduceFunction- A JavaScript function that "reduces" to a single object all the values associated with a particular key.- Returns:
- an Promise containing the result of the map-reduce operation
-
getMaxItemsPerQuery
public final int getMaxItemsPerQuery() -
setMaxItemsPerQuery
public final void setMaxItemsPerQuery(int maxItemsPerQuery) -
getCollection
public final com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> getCollection() -
setCollection
public final void setCollection(com.mongodb.reactivestreams.client.MongoCollection<org.bson.Document> collection)
-