public class MongoTemplate extends Object implements MongoOperations, ApplicationContextAware, IndexOperationsProvider
MongoOperations.ExecutableFindOperation.ExecutableFind<T>, ExecutableFindOperation.FindWithCollection<T>, ExecutableFindOperation.FindWithProjection<T>, ExecutableFindOperation.FindWithQuery<T>, ExecutableFindOperation.TerminatingFind<T>, ExecutableFindOperation.TerminatingFindNear<T>ExecutableInsertOperation.ExecutableInsert<T>, ExecutableInsertOperation.InsertWithBulkMode<T>, ExecutableInsertOperation.InsertWithCollection<T>, ExecutableInsertOperation.TerminatingBulkInsert<T>, ExecutableInsertOperation.TerminatingInsert<T>ExecutableUpdateOperation.ExecutableUpdate<T>, ExecutableUpdateOperation.FindAndModifyWithOptions<T>, ExecutableUpdateOperation.TerminatingFindAndModify<T>, ExecutableUpdateOperation.TerminatingUpdate<T>, ExecutableUpdateOperation.UpdateWithCollection<T>, ExecutableUpdateOperation.UpdateWithQuery<T>, ExecutableUpdateOperation.UpdateWithUpdate<T>ExecutableRemoveOperation.ExecutableRemove<T>, ExecutableRemoveOperation.RemoveWithCollection<T>, ExecutableRemoveOperation.RemoveWithQuery<T>, ExecutableRemoveOperation.TerminatingRemove<T>ExecutableAggregationOperation.AggregationWithAggregation<T>, ExecutableAggregationOperation.AggregationWithCollection<T>, ExecutableAggregationOperation.ExecutableAggregation<T>, ExecutableAggregationOperation.TerminatingAggregation<T>| Constructor and Description |
|---|
MongoTemplate(com.mongodb.MongoClient mongoClient,
String databaseName)
Constructor used for a basic template configuration
|
MongoTemplate(MongoDbFactory mongoDbFactory)
Constructor used for a basic template configuration.
|
MongoTemplate(MongoDbFactory mongoDbFactory,
MongoConverter mongoConverter)
Constructor used for a basic template configuration.
|
| Modifier and Type | Method and Description |
|---|---|
<O> AggregationResults<O> |
aggregate(Aggregation aggregation,
Class<?> inputType,
Class<O> outputType)
Execute an aggregation operation.
|
<O> AggregationResults<O> |
aggregate(Aggregation aggregation,
String collectionName,
Class<O> outputType)
Execute an aggregation operation.
|
protected <O> AggregationResults<O> |
aggregate(Aggregation aggregation,
String collectionName,
Class<O> outputType,
AggregationOperationContext context) |
<O> AggregationResults<O> |
aggregate(TypedAggregation<?> aggregation,
Class<O> outputType)
Execute an aggregation operation.
|
<O> AggregationResults<O> |
aggregate(TypedAggregation<?> aggregation,
String inputCollectionName,
Class<O> outputType)
Execute an aggregation operation.
|
<T> ExecutableAggregationOperation.ExecutableAggregation<T> |
aggregateAndReturn(Class<T> domainType)
Start creating an aggregation operation that returns results mapped to the given domain type.
|
<O> CloseableIterator<O> |
aggregateStream(Aggregation aggregation,
Class<?> inputType,
Class<O> outputType)
Execute an aggregation operation backed by a Mongo DB
Cursor. |
<O> CloseableIterator<O> |
aggregateStream(Aggregation aggregation,
String collectionName,
Class<O> outputType)
Execute an aggregation operation backed by a Mongo DB
Cursor. |
protected <O> CloseableIterator<O> |
aggregateStream(Aggregation aggregation,
String collectionName,
Class<O> outputType,
AggregationOperationContext context) |
<O> CloseableIterator<O> |
aggregateStream(TypedAggregation<?> aggregation,
Class<O> outputType)
Execute an aggregation operation backed by a Mongo DB
Cursor. |
<O> CloseableIterator<O> |
aggregateStream(TypedAggregation<?> aggregation,
String inputCollectionName,
Class<O> outputType)
Execute an aggregation operation backed by a Mongo DB
Cursor. |
BulkOperations |
bulkOps(BulkOperations.BulkMode bulkMode,
Class<?> entityClass)
Returns a new
BulkOperations for the given entity type. |
BulkOperations |
bulkOps(BulkOperations.BulkMode mode,
Class<?> entityType,
String collectionName)
Returns a new
BulkOperations for the given entity type and collection name. |
BulkOperations |
bulkOps(BulkOperations.BulkMode bulkMode,
String collectionName)
Returns a new
BulkOperations for the given collection. |
<T> boolean |
collectionExists(Class<T> entityClass)
Check to see if a collection with a name indicated by the entity class exists.
|
boolean |
collectionExists(String collectionName)
Check to see if a collection with a given name exists.
|
protected org.bson.Document |
convertToDocument(CollectionOptions collectionOptions) |
long |
count(Query query,
Class<?> entityClass)
Returns the number of documents for the given
Query by querying the collection of the given entity class. |
long |
count(Query query,
Class<?> entityClass,
String collectionName)
|
long |
count(Query query,
String collectionName)
Returns the number of documents for the given
Query querying the given collection. |
<T> com.mongodb.client.MongoCollection<org.bson.Document> |
createCollection(Class<T> entityClass)
Create an uncapped collection with a name based on the provided entity class.
|
<T> com.mongodb.client.MongoCollection<org.bson.Document> |
createCollection(Class<T> entityClass,
CollectionOptions collectionOptions)
Create a collection with a name based on the provided entity class using the options.
|
com.mongodb.client.MongoCollection<org.bson.Document> |
createCollection(String collectionName)
Create an uncapped collection with the provided name.
|
com.mongodb.client.MongoCollection<org.bson.Document> |
createCollection(String collectionName,
CollectionOptions collectionOptions)
Create a collection with the provided name and options.
|
protected com.mongodb.client.MongoCollection<org.bson.Document> |
doCreateCollection(String collectionName,
org.bson.Document collectionOptions)
Create the specified collection using the provided options
|
protected <S,T> List<T> |
doFind(String collectionName,
org.bson.Document query,
org.bson.Document fields,
Class<S> entityClass,
org.springframework.data.mongodb.core.CursorPreparer preparer,
org.springframework.data.mongodb.core.MongoTemplate.DocumentCallback<T> objectCallback) |
protected <T> List<T> |
doFind(String collectionName,
org.bson.Document query,
org.bson.Document fields,
Class<T> entityClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter.
|
protected <T> List<T> |
doFind(String collectionName,
org.bson.Document query,
org.bson.Document fields,
Class<T> entityClass,
org.springframework.data.mongodb.core.CursorPreparer preparer)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
|
protected <T> List<T> |
doFindAndDelete(String collectionName,
Query query,
Class<T> entityClass)
Retrieve and remove all documents matching the given
query by calling find(Query, Class, String)
and remove(Query, Class, String), whereas the Query for remove(Query, Class, String) is
constructed out of the find result. |
protected <T> T |
doFindAndModify(String collectionName,
org.bson.Document query,
org.bson.Document fields,
org.bson.Document sort,
Class<T> entityClass,
Update update,
FindAndModifyOptions options) |
protected <T> T |
doFindAndRemove(String collectionName,
org.bson.Document query,
org.bson.Document fields,
org.bson.Document sort,
Collation collation,
Class<T> entityClass)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
|
protected <T> T |
doFindOne(String collectionName,
org.bson.Document query,
org.bson.Document fields,
Class<T> entityClass)
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
|
protected <T> void |
doInsert(String collectionName,
T objectToSave,
MongoWriter<T> writer) |
protected <T> void |
doInsertAll(Collection<? extends T> listToSave,
MongoWriter<T> writer) |
protected <T> void |
doInsertBatch(String collectionName,
Collection<? extends T> batchToSave,
MongoWriter<T> writer) |
protected <T> com.mongodb.client.result.DeleteResult |
doRemove(String collectionName,
Query query,
Class<T> entityClass) |
protected <T> T |
doSave(String collectionName,
T objectToSave,
MongoWriter<T> writer) |
protected <T> CloseableIterator<T> |
doStream(Query query,
Class<?> entityType,
String collectionName,
Class<T> returnType) |
protected com.mongodb.client.result.UpdateResult |
doUpdate(String collectionName,
Query query,
Update update,
Class<?> entityClass,
boolean upsert,
boolean multi) |
<T> void |
dropCollection(Class<T> entityClass)
Drop the collection with the name indicated by the entity class.
|
void |
dropCollection(String collectionName)
Drop the collection with the given name.
|
protected void |
ensureNotIterable(Object o) |
<T> T |
execute(Class<?> entityClass,
CollectionCallback<T> callback)
Executes the given
CollectionCallback on the entity collection of the specified class. |
<T> T |
execute(DbCallback<T> action)
Executes a
DbCallback translating any exceptions as necessary. |
<T> T |
execute(String collectionName,
CollectionCallback<T> callback)
Executes the given
CollectionCallback on the collection of the given name. |
org.bson.Document |
executeCommand(org.bson.Document command)
Execute a MongoDB command.
|
org.bson.Document |
executeCommand(org.bson.Document command,
com.mongodb.ReadPreference readPreference)
Execute a MongoDB command.
|
org.bson.Document |
executeCommand(String jsonCommand)
Execute the a MongoDB command expressed as a JSON string.
|
void |
executeQuery(Query query,
String collectionName,
DocumentCallbackHandler dch)
Execute a MongoDB query and iterate over the query results on a per-document basis with a DocumentCallbackHandler.
|
protected void |
executeQuery(Query query,
String collectionName,
DocumentCallbackHandler dch,
org.springframework.data.mongodb.core.CursorPreparer preparer)
Execute a MongoDB query and iterate over the query results on a per-document basis with a
DocumentCallbackHandler using the provided CursorPreparer. |
boolean |
exists(Query query,
Class<?> entityClass)
Determine result of given
Query contains at least one element. |
boolean |
exists(Query query,
Class<?> entityClass,
String collectionName)
Determine result of given
Query contains at least one element. |
boolean |
exists(Query query,
String collectionName)
Determine result of given
Query contains at least one element. |
<T> List<T> |
find(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
|
<T> List<T> |
find(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a List of the specified type.
|
<T> List<T> |
findAll(Class<T> entityClass)
Query for a list of objects of type T from the collection used by the entity class.
|
<T> List<T> |
findAll(Class<T> entityClass,
String collectionName)
Query for a list of objects of type T from the specified collection.
|
<T> List<T> |
findAllAndRemove(Query query,
Class<T> entityClass)
Returns and removes all documents matching the given query form the collection used to store the entityClass.
|
<T> List<T> |
findAllAndRemove(Query query,
Class<T> entityClass,
String collectionName)
Returns and removes all documents that match the provided query document criteria from the the collection used to
store the entityClass.
|
<T> List<T> |
findAllAndRemove(Query query,
String collectionName)
Returns and removes all documents form the specified collection that match the provided query.
|
<T> T |
findAndModify(Query query,
Update update,
Class<T> entityClass)
|
<T> T |
findAndModify(Query query,
Update update,
Class<T> entityClass,
String collectionName)
|
<T> T |
findAndModify(Query query,
Update update,
FindAndModifyOptions options,
Class<T> entityClass)
Triggers findAndModify
to apply provided
Update on documents matching Criteria of given Query taking
FindAndModifyOptions into account. |
<T> T |
findAndModify(Query query,
Update update,
FindAndModifyOptions options,
Class<T> entityClass,
String collectionName)
Triggers findAndModify
to apply provided
Update on documents matching Criteria of given Query taking
FindAndModifyOptions into account. |
<T> T |
findAndRemove(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity type to a single instance of an object of the
specified type.
|
<T> T |
findAndRemove(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
type.
|
<T> T |
findById(Object id,
Class<T> entityClass)
Returns a document with the given id mapped onto the given class.
|
<T> T |
findById(Object id,
Class<T> entityClass,
String collectionName)
Returns the document with the given id from the given collection mapped onto the given target class.
|
<T> T |
findOne(Query query,
Class<T> entityClass)
Map the results of an ad-hoc query on the collection for the entity class to a single instance of an object of the
specified type.
|
<T> T |
findOne(Query query,
Class<T> entityClass,
String collectionName)
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
type.
|
<T> GeoResults<T> |
geoNear(NearQuery near,
Class<?> domainType,
String collectionName,
Class<T> returnType) |
<T> GeoResults<T> |
geoNear(NearQuery near,
Class<T> entityClass)
Returns
GeoResults for all entities matching the given NearQuery. |
<T> GeoResults<T> |
geoNear(NearQuery near,
Class<T> domainType,
String collectionName)
Returns
GeoResults for all entities matching the given NearQuery. |
com.mongodb.client.MongoCollection<org.bson.Document> |
getCollection(String collectionName)
Get a collection by name, creating it if it doesn't exist.
|
String |
getCollectionName(Class<?> entityClass)
The collection name used for the specified class by this template.
|
Set<String> |
getCollectionNames()
A set of collection names.
|
MongoConverter |
getConverter()
Returns the default
MongoConverter. |
com.mongodb.client.MongoDatabase |
getDb() |
PersistenceExceptionTranslator |
getExceptionTranslator() |
MongoDbFactory |
getMongoDbFactory() |
<T> GroupByResults<T> |
group(Criteria criteria,
String inputCollectionName,
GroupBy groupBy,
Class<T> entityClass)
Execute a group operation restricting the rows to those which match the provided Criteria.
|
<T> GroupByResults<T> |
group(String inputCollectionName,
GroupBy groupBy,
Class<T> entityClass)
Execute a group operation over the entire collection.
|
IndexOperations |
indexOps(Class<?> entityClass)
Returns the operations that can be performed on indexes
|
IndexOperations |
indexOps(String collectionName)
Returns the operations that can be performed on indexes
|
<T> ExecutableInsertOperation.ExecutableInsert<T> |
insert(Class<T> domainType)
Start creating an insert operation for given domainType.
|
void |
insert(Collection<? extends Object> batchToSave,
Class<?> entityClass)
Insert a Collection of objects into a collection in a single batch write to the database.
|
void |
insert(Collection<? extends Object> batchToSave,
String collectionName)
Insert a list of objects into the specified collection in a single batch write to the database.
|
void |
insert(Object objectToSave)
Insert the object into the collection for the entity type of the object to save.
|
void |
insert(Object objectToSave,
String collectionName)
Insert the object into the specified collection.
|
void |
insertAll(Collection<? extends Object> objectsToSave)
Insert a mixed Collection of objects into a database collection determining the collection name to use based on the
class.
|
protected Object |
insertDocument(String collectionName,
org.bson.Document document,
Class<?> entityClass) |
protected List<Object> |
insertDocumentList(String collectionName,
List<org.bson.Document> documents) |
<T> MapReduceResults<T> |
mapReduce(Query query,
String inputCollectionName,
String mapFunction,
String reduceFunction,
Class<T> entityClass)
Execute a map-reduce operation that takes a query.
|
<T> MapReduceResults<T> |
mapReduce(Query query,
String inputCollectionName,
String mapFunction,
String reduceFunction,
MapReduceOptions mapReduceOptions,
Class<T> entityClass)
Execute a map-reduce operation that takes a query and additional map-reduce options
|
<T> MapReduceResults<T> |
mapReduce(String inputCollectionName,
String mapFunction,
String reduceFunction,
Class<T> entityClass)
Execute a map-reduce operation.
|
<T> MapReduceResults<T> |
mapReduce(String inputCollectionName,
String mapFunction,
String reduceFunction,
MapReduceOptions mapReduceOptions,
Class<T> entityClass)
Execute a map-reduce operation that takes additional map-reduce options.
|
protected <T> void |
maybeEmitEvent(MongoMappingEvent<T> event) |
protected void |
populateIdIfNecessary(Object savedObject,
Object id)
Populates the id property of the saved object, if it's not set already.
|
protected com.mongodb.client.MongoCollection<org.bson.Document> |
prepareCollection(com.mongodb.client.MongoCollection<org.bson.Document> collection)
Prepare the collection before any processing is done using it.
|
protected com.mongodb.WriteConcern |
prepareWriteConcern(MongoAction mongoAction)
Prepare the WriteConcern before any processing is done using it.
|
<T> ExecutableFindOperation.ExecutableFind<T> |
query(Class<T> domainType)
Start creating a find operation for the given domainType.
|
<T> ExecutableRemoveOperation.ExecutableRemove<T> |
remove(Class<T> domainType)
Start creating a remove operation for the given domainType.
|
com.mongodb.client.result.DeleteResult |
remove(Object object)
Remove the given object from the collection by id.
|
com.mongodb.client.result.DeleteResult |
remove(Object object,
String collection)
Removes the given object from the given collection.
|
com.mongodb.client.result.DeleteResult |
remove(Query query,
Class<?> entityClass)
Remove all documents that match the provided query document criteria from the the collection used to store the
entityClass.
|
com.mongodb.client.result.DeleteResult |
remove(Query query,
Class<?> entityClass,
String collectionName)
Remove all documents that match the provided query document criteria from the the collection used to store the
entityClass.
|
com.mongodb.client.result.DeleteResult |
remove(Query query,
String collectionName)
Remove all documents from the specified collection that match the provided query document criteria.
|
protected String |
replaceWithResourceIfNecessary(String function) |
void |
save(Object objectToSave)
Save the object to the collection for the entity type of the object to save.
|
void |
save(Object objectToSave,
String collectionName)
Save the object to the specified collection.
|
protected Object |
saveDocument(String collectionName,
org.bson.Document dbDoc,
Class<?> entityClass) |
ScriptOperations |
scriptOps()
Returns the
ScriptOperations that can be performed on DB level. |
void |
setApplicationContext(ApplicationContext applicationContext) |
void |
setReadPreference(com.mongodb.ReadPreference readPreference)
Used by @{link
prepareCollection(MongoCollection) to set the ReadPreference before any operations
are performed. |
void |
setWriteConcern(com.mongodb.WriteConcern writeConcern)
Configures the
WriteConcern to be used with the template. |
void |
setWriteConcernResolver(WriteConcernResolver writeConcernResolver)
Configures the
WriteConcernResolver to be used with the template. |
void |
setWriteResultChecking(WriteResultChecking resultChecking)
Configures the
WriteResultChecking to be used with the template. |
<T> CloseableIterator<T> |
stream(Query query,
Class<T> entityType)
Executes the given
Query on the entity collection of the specified entityType backed by a Mongo DB
Cursor. |
<T> CloseableIterator<T> |
stream(Query query,
Class<T> entityType,
String collectionName)
Executes the given
Query on the entity collection of the specified entityType and collection backed
by a Mongo DB Cursor. |
<T> ExecutableUpdateOperation.ExecutableUpdate<T> |
update(Class<T> domainType)
Start creating an update operation for the given domainType.
|
com.mongodb.client.result.UpdateResult |
updateFirst(Query query,
Update update,
Class<?> entityClass)
Updates the first object that is found in the collection of the entity class that matches the query document with
the provided update document.
|
com.mongodb.client.result.UpdateResult |
updateFirst(Query query,
Update update,
Class<?> entityClass,
String collectionName)
Updates the first object that is found in the specified collection that matches the query document criteria with
the provided updated document.
|
com.mongodb.client.result.UpdateResult |
updateFirst(Query query,
Update update,
String collectionName)
Updates the first object that is found in the specified collection that matches the query document criteria with
the provided updated document.
|
com.mongodb.client.result.UpdateResult |
updateMulti(Query query,
Update update,
Class<?> entityClass)
Updates all objects that are found in the collection for the entity class that matches the query document criteria
with the provided updated document.
|
com.mongodb.client.result.UpdateResult |
updateMulti(Query query,
Update update,
Class<?> entityClass,
String collectionName)
Updates all objects that are found in the collection for the entity class that matches the query document criteria
with the provided updated document.
|
com.mongodb.client.result.UpdateResult |
updateMulti(Query query,
Update update,
String collectionName)
Updates all objects that are found in the specified collection that matches the query document criteria with the
provided updated document.
|
com.mongodb.client.result.UpdateResult |
upsert(Query query,
Update update,
Class<?> entityClass)
Performs an upsert.
|
com.mongodb.client.result.UpdateResult |
upsert(Query query,
Update update,
Class<?> entityClass,
String collectionName)
Performs an upsert.
|
com.mongodb.client.result.UpdateResult |
upsert(Query query,
Update update,
String collectionName)
Performs an upsert.
|
public MongoTemplate(com.mongodb.MongoClient mongoClient,
String databaseName)
mongoClient - must not be null.databaseName - must not be null or empty.public MongoTemplate(MongoDbFactory mongoDbFactory)
mongoDbFactory - must not be null.public MongoTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter)
mongoDbFactory - must not be null.mongoConverter - public void setWriteResultChecking(WriteResultChecking resultChecking)
WriteResultChecking to be used with the template. Setting null will reset the
default of DEFAULT_WRITE_RESULT_CHECKING.resultChecking - public void setWriteConcern(com.mongodb.WriteConcern writeConcern)
WriteConcern to be used with the template. If none is configured the WriteConcern
configured on the MongoDbFactory will apply. If you configured a Mongo instance no
WriteConcern will be used.writeConcern - public void setWriteConcernResolver(WriteConcernResolver writeConcernResolver)
WriteConcernResolver to be used with the template.writeConcernResolver - public void setReadPreference(com.mongodb.ReadPreference readPreference)
prepareCollection(MongoCollection) to set the ReadPreference before any operations
are performed.readPreference - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException
setApplicationContext in interface ApplicationContextAwareBeansExceptionpublic MongoConverter getConverter()
MongoConverter.getConverter in interface MongoOperationspublic <T> CloseableIterator<T> stream(Query query, Class<T> entityType)
MongoOperationsQuery on the entity collection of the specified entityType backed by a Mongo DB
Cursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed.
stream in interface MongoOperationsT - element return typequery - must not be null.entityType - must not be null.public <T> CloseableIterator<T> stream(Query query, Class<T> entityType, String collectionName)
MongoOperationsQuery on the entity collection of the specified entityType and collection backed
by a Mongo DB Cursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed.
stream in interface MongoOperationsT - element return typequery - must not be null.entityType - must not be null.collectionName - must not be null or empty.protected <T> CloseableIterator<T> doStream(Query query, Class<?> entityType, String collectionName, Class<T> returnType)
public String getCollectionName(Class<?> entityClass)
MongoOperationsgetCollectionName in interface MongoOperationsentityClass - must not be null.public org.bson.Document executeCommand(String jsonCommand)
MongoOperationsexecuteCommand in interface MongoOperationsjsonCommand - a MongoDB command expressed as a JSON string.public org.bson.Document executeCommand(org.bson.Document command)
MongoOperationsexecuteCommand in interface MongoOperationscommand - a MongoDB commandpublic org.bson.Document executeCommand(org.bson.Document command,
com.mongodb.ReadPreference readPreference)
MongoOperationsexecuteCommand in interface MongoOperationscommand - a MongoDB command, must not be null.readPreference - read preferences to use, can be null.public void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch)
MongoOperationsexecuteQuery in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationcollectionName - name of the collection to retrieve the objects fromdch - the handler that will extract results, one document at a timeprotected void executeQuery(Query query, String collectionName, DocumentCallbackHandler dch, org.springframework.data.mongodb.core.CursorPreparer preparer)
DocumentCallbackHandler using the provided CursorPreparer.query - the query class that specifies the criteria used to find a record and also an optional fields
specification, must not be null.collectionName - name of the collection to retrieve the objects fromdch - the handler that will extract results, one document at a timepreparer - allows for customization of the DBCursor used when iterating over the result set, (apply
limits, skips and so on).public <T> T execute(DbCallback<T> action)
MongoOperationsDbCallback translating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.execute in interface MongoOperationsT - return typeaction - callback object that specifies the MongoDB actions to perform on the passed in DB instance.public <T> T execute(Class<?> entityClass, CollectionCallback<T> callback)
MongoOperationsCollectionCallback on the entity collection of the specified class.
Allows for returning a result object, that is a domain object or a collection of domain objects.execute in interface MongoOperationsT - return typeentityClass - class that determines the collection to usecallback - callback object that specifies the MongoDB actionpublic <T> T execute(String collectionName, CollectionCallback<T> callback)
MongoOperationsCollectionCallback on the collection of the given name.
Allows for returning a result object, that is a domain object or a collection of domain objects.execute in interface MongoOperationsT - return typecollectionName - the name of the collection that specifies which DBCollection instance will be passed intocallback - callback object that specifies the MongoDB action the callback action.public <T> com.mongodb.client.MongoCollection<org.bson.Document> createCollection(Class<T> entityClass)
MongoOperationscreateCollection in interface MongoOperationsentityClass - class that determines the collection to createpublic <T> com.mongodb.client.MongoCollection<org.bson.Document> createCollection(Class<T> entityClass, CollectionOptions collectionOptions)
MongoOperationscreateCollection in interface MongoOperationsentityClass - class that determines the collection to createcollectionOptions - options to use when creating the collection.public com.mongodb.client.MongoCollection<org.bson.Document> createCollection(String collectionName)
MongoOperationscreateCollection in interface MongoOperationscollectionName - name of the collectionpublic com.mongodb.client.MongoCollection<org.bson.Document> createCollection(String collectionName, CollectionOptions collectionOptions)
MongoOperationscreateCollection in interface MongoOperationscollectionName - name of the collectioncollectionOptions - options to use when creating the collection.public com.mongodb.client.MongoCollection<org.bson.Document> getCollection(String collectionName)
MongoOperationsgetCollection in interface MongoOperationscollectionName - name of the collectionpublic <T> boolean collectionExists(Class<T> entityClass)
MongoOperationscollectionExists in interface MongoOperationsentityClass - class that determines the name of the collectionpublic boolean collectionExists(String collectionName)
MongoOperationscollectionExists in interface MongoOperationscollectionName - name of the collectionpublic <T> void dropCollection(Class<T> entityClass)
MongoOperationsdropCollection in interface MongoOperationsentityClass - class that determines the collection to drop/delete.public void dropCollection(String collectionName)
MongoOperationsdropCollection in interface MongoOperationscollectionName - name of the collection to drop/delete.public IndexOperations indexOps(String collectionName)
MongoOperationsindexOps in interface IndexOperationsProviderindexOps in interface MongoOperationspublic IndexOperations indexOps(Class<?> entityClass)
MongoOperationsindexOps in interface MongoOperationspublic BulkOperations bulkOps(BulkOperations.BulkMode bulkMode, String collectionName)
MongoOperationsBulkOperations for the given collection. #bulkOps(BulkMode, Class, String) to get full type specific support.bulkOps in interface MongoOperationsbulkMode - the BulkOperations.BulkMode to use for bulk operations, must not be null.collectionName - the name of the collection to work on, must not be null or empty.BulkOperations on the named collectionpublic BulkOperations bulkOps(BulkOperations.BulkMode bulkMode, Class<?> entityClass)
MongoOperationsBulkOperations for the given entity type.bulkOps in interface MongoOperationsbulkMode - the BulkOperations.BulkMode to use for bulk operations, must not be null.entityClass - the name of the entity class, must not be null.BulkOperations on the named collection associated of the given entity class.public BulkOperations bulkOps(BulkOperations.BulkMode mode, Class<?> entityType, String collectionName)
MongoOperationsBulkOperations for the given entity type and collection name.bulkOps in interface MongoOperationsmode - the BulkOperations.BulkMode to use for bulk operations, must not be null.collectionName - the name of the collection to work on, must not be null or empty.BulkOperations on the named collection associated with the given entity class.public ScriptOperations scriptOps()
MongoOperationsScriptOperations that can be performed on DB level.scriptOps in interface MongoOperationspublic <T> T findOne(Query query, Class<T> entityClass)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.findOne in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.public <T> T findOne(Query query, Class<T> entityClass, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.findOne in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.collectionName - name of the collection to retrieve the objects frompublic boolean exists(Query query, Class<?> entityClass)
MongoOperationsQuery contains at least one element.exists in interface MongoOperationsquery - the Query class that specifies the criteria used to find a record.entityClass - the parametrized type.public boolean exists(Query query, String collectionName)
MongoOperationsQuery contains at least one element. MongoOperations.exists(Query, Class, String) to get full type specific support.exists in interface MongoOperationsquery - the Query class that specifies the criteria used to find a record.collectionName - name of the collection to check for objects.public boolean exists(Query query, Class<?> entityClass, String collectionName)
MongoOperationsQuery contains at least one element.exists in interface MongoOperationsquery - the Query class that specifies the criteria used to find a record.entityClass - the parametrized type.collectionName - name of the collection to check for objects.public <T> List<T> find(Query query, Class<T> entityClass)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.find in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.public <T> List<T> find(Query query, Class<T> entityClass, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.find in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.collectionName - name of the collection to retrieve the objects frompublic <T> T findById(Object id, Class<T> entityClass)
MongoOperationsfindById in interface MongoOperationsid - the id of the document to return.entityClass - the type the document shall be converted into.public <T> T findById(Object id, Class<T> entityClass, String collectionName)
MongoOperationsfindById in interface MongoOperationsid - the id of the document to returnentityClass - the type to convert the document tocollectionName - the collection to query for the documentpublic <T> GeoResults<T> geoNear(NearQuery near, Class<T> entityClass)
MongoOperationsGeoResults for all entities matching the given NearQuery. Will consider entity mapping
information to determine the collection the query is ran against. Note, that MongoDB limits the number of results
by default. Make sure to add an explicit limit to the NearQuery if you expect a particular number of
results.geoNear in interface MongoOperationsnear - must not be null.entityClass - must not be null.public <T> GeoResults<T> geoNear(NearQuery near, Class<T> domainType, String collectionName)
MongoOperationsGeoResults for all entities matching the given NearQuery. Note, that MongoDB limits the
number of results by default. Make sure to add an explicit limit to the NearQuery if you expect a
particular number of results.geoNear in interface MongoOperationsnear - must not be null.domainType - must not be null.collectionName - the collection to trigger the query against. If no collection name is given the entity class
will be inspected.public <T> GeoResults<T> geoNear(NearQuery near, Class<?> domainType, String collectionName, Class<T> returnType)
public <T> T findAndModify(Query query, Update update, Class<T> entityClass)
MongoOperationsfindAndModify in interface MongoOperationsquery - the Query class that specifies the Criteria used to find a record and also an optional
fields specification.update - the Update to apply on matching documents.entityClass - the parametrized type.public <T> T findAndModify(Query query, Update update, Class<T> entityClass, String collectionName)
MongoOperationsfindAndModify in interface MongoOperationsquery - the Query class that specifies the Criteria used to find a record and also an optional
fields specification.update - the Update to apply on matching documents.entityClass - the parametrized type.collectionName - the collection to query.public <T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass)
MongoOperationsUpdate on documents matching Criteria of given Query taking
FindAndModifyOptions into account.findAndModify in interface MongoOperationsquery - the Query class that specifies the Criteria used to find a record and also an optional
fields specification.update - the Update to apply on matching documents.options - the FindAndModifyOptions holding additional information.entityClass - the parametrized type.public <T> T findAndModify(Query query, Update update, FindAndModifyOptions options, Class<T> entityClass, String collectionName)
MongoOperationsUpdate on documents matching Criteria of given Query taking
FindAndModifyOptions into account.findAndModify in interface MongoOperationsquery - the Query class that specifies the Criteria used to find a record and also an optional
fields specification.update - the Update to apply on matching documents.options - the FindAndModifyOptions holding additional information.entityClass - the parametrized type.collectionName - the collection to query.public <T> T findAndRemove(Query query, Class<T> entityClass)
MongoOperationsMongoConverter.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.findAndRemove in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.public <T> T findAndRemove(Query query, Class<T> entityClass, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.findAndRemove in interface MongoOperationsquery - the query class that specifies the criteria used to find a record and also an optional fields
specificationentityClass - the parametrized type of the returned list.collectionName - name of the collection to retrieve the objects frompublic long count(Query query, Class<?> entityClass)
MongoOperationsQuery by querying the collection of the given entity class.count in interface MongoOperationsentityClass - must not be null.public long count(Query query, String collectionName)
MongoOperationsQuery querying the given collection. The given Query
must solely consist of document field references as we lack type information to map potential property references
onto document fields. Use MongoOperations.count(Query, Class, String) to get full type specific support.count in interface MongoOperationscollectionName - must not be null or empty.MongoOperations.count(Query, Class, String)public long count(Query query, Class<?> entityClass, String collectionName)
MongoOperationsQuery by querying the given collection using the given entity
class to map the given Query.count in interface MongoOperationsentityClass - must not be null.collectionName - must not be null or empty.public void insert(Object objectToSave)
MongoOperationsMongoConverter.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
Spring's Type Conversion" for more details.
Insert is used to initially store the object into the database. To update an existing object use the save method.insert in interface MongoOperationsobjectToSave - the object to store in the collection.public void insert(Object objectToSave, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
Insert is used to initially store the object into the database. To update an existing object use the save method.insert in interface MongoOperationsobjectToSave - the object to store in the collectioncollectionName - name of the collection to store the object inprotected void ensureNotIterable(Object o)
protected com.mongodb.client.MongoCollection<org.bson.Document> prepareCollection(com.mongodb.client.MongoCollection<org.bson.Document> collection)
collection - protected com.mongodb.WriteConcern prepareWriteConcern(MongoAction mongoAction)
WriteConcern will be defaulted to
WriteConcern.ACKNOWLEDGED when WriteResultChecking is set to WriteResultChecking.EXCEPTION.writeConcern - any WriteConcern already configured or nullprotected <T> void doInsert(String collectionName, T objectToSave, MongoWriter<T> writer)
public void insert(Collection<? extends Object> batchToSave, Class<?> entityClass)
MongoOperationsinsert in interface MongoOperationsbatchToSave - the list of objects to save.entityClass - class that determines the collection to usepublic void insert(Collection<? extends Object> batchToSave, String collectionName)
MongoOperationsinsert in interface MongoOperationsbatchToSave - the list of objects to save.collectionName - name of the collection to store the object inpublic void insertAll(Collection<? extends Object> objectsToSave)
MongoOperationsinsertAll in interface MongoOperationsprotected <T> void doInsertAll(Collection<? extends T> listToSave, MongoWriter<T> writer)
protected <T> void doInsertBatch(String collectionName, Collection<? extends T> batchToSave, MongoWriter<T> writer)
public void save(Object objectToSave)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Type Conversion API. See
Spring's Type Conversion" for more details.save in interface MongoOperationsobjectToSave - the object to store in the collectionpublic void save(Object objectToSave, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
If you object has an "Id' property, it will be set with the generated Id from MongoDB. If your Id property is a
String then MongoDB ObjectId will be used to populate that string. Otherwise, the conversion from ObjectId to your
property type will be handled by Spring's BeanWrapper class that leverages Type Cobnversion API. See Spring's
Type Conversion" for more details.save in interface MongoOperationsobjectToSave - the object to store in the collectioncollectionName - name of the collection to store the object inprotected <T> T doSave(String collectionName, T objectToSave, MongoWriter<T> writer)
protected Object insertDocument(String collectionName, org.bson.Document document, Class<?> entityClass)
protected List<Object> insertDocumentList(String collectionName, List<org.bson.Document> documents)
protected Object saveDocument(String collectionName, org.bson.Document dbDoc, Class<?> entityClass)
public com.mongodb.client.result.UpdateResult upsert(Query query, Update update, Class<?> entityClass)
MongoOperationsupsert in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be upsertedupdate - the update document that contains the updated object or $ operators to manipulate the existing objectentityClass - class that determines the collection to usepublic com.mongodb.client.result.UpdateResult upsert(Query query, Update update, String collectionName)
MongoOperationsMongoOperations.upsert(Query, Update, Class, String) to get full type specific support.upsert in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.collectionName - name of the collection to update the object inpublic com.mongodb.client.result.UpdateResult upsert(Query query, Update update, Class<?> entityClass, String collectionName)
MongoOperationsupsert in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be upsertedupdate - the update document that contains the updated object or $ operators to manipulate the existing objectentityClass - class of the pojo to be operated oncollectionName - name of the collection to update the object inpublic com.mongodb.client.result.UpdateResult updateFirst(Query query, Update update, Class<?> entityClass)
MongoOperationsupdateFirst in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.entityClass - class that determines the collection to usepublic com.mongodb.client.result.UpdateResult updateFirst(Query query, Update update, String collectionName)
MongoOperationsMongoOperations.updateFirst(Query, Update, Class, String) to get full type specific support.updateFirst in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.collectionName - name of the collection to update the object inpublic com.mongodb.client.result.UpdateResult updateFirst(Query query, Update update, Class<?> entityClass, String collectionName)
MongoOperationsupdateFirst in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.entityClass - class of the pojo to be operated oncollectionName - name of the collection to update the object inpublic com.mongodb.client.result.UpdateResult updateMulti(Query query, Update update, Class<?> entityClass)
MongoOperationsupdateMulti in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.entityClass - class that determines the collection to usepublic com.mongodb.client.result.UpdateResult updateMulti(Query query, Update update, String collectionName)
MongoOperationsMongoOperations.updateMulti(Query, Update, Class, String) to get full type specific support.updateMulti in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.collectionName - name of the collection to update the object inpublic com.mongodb.client.result.UpdateResult updateMulti(Query query, Update update, Class<?> entityClass, String collectionName)
MongoOperationsupdateMulti in interface MongoOperationsquery - the query document that specifies the criteria used to select a record to be updatedupdate - the update document that contains the updated object or $ operators to manipulate the existing
object.entityClass - class of the pojo to be operated oncollectionName - name of the collection to update the object inprotected com.mongodb.client.result.UpdateResult doUpdate(String collectionName, Query query, Update update, Class<?> entityClass, boolean upsert, boolean multi)
public com.mongodb.client.result.DeleteResult remove(Object object)
MongoOperationsremove in interface MongoOperationspublic com.mongodb.client.result.DeleteResult remove(Object object, String collection)
MongoOperationsremove in interface MongoOperationscollection - must not be null or empty.public com.mongodb.client.result.DeleteResult remove(Query query, String collectionName)
MongoOperationsMongoOperations.remove(Query, Class, String) to get full type specific support.remove in interface MongoOperationsquery - the query document that specifies the criteria used to remove a recordcollectionName - name of the collection where the objects will removedpublic com.mongodb.client.result.DeleteResult remove(Query query, Class<?> entityClass)
MongoOperationsremove in interface MongoOperationspublic com.mongodb.client.result.DeleteResult remove(Query query, Class<?> entityClass, String collectionName)
MongoOperationsremove in interface MongoOperationsprotected <T> com.mongodb.client.result.DeleteResult doRemove(String collectionName, Query query, Class<T> entityClass)
public <T> List<T> findAll(Class<T> entityClass)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
to map objects since the test for class type is done in the client and not on the server.findAll in interface MongoOperationsentityClass - the parametrized type of the returned listpublic <T> List<T> findAll(Class<T> entityClass, String collectionName)
MongoOperationsMongoConverter. Unless
configured otherwise, an instance of MappingMongoConverter will be used.
If your collection does not contain a homogeneous collection of types, this operation will not be an efficient way
to map objects since the test for class type is done in the client and not on the server.findAll in interface MongoOperationsentityClass - the parametrized type of the returned list.collectionName - name of the collection to retrieve the objects frompublic <T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction, Class<T> entityClass)
MongoOperationsmapReduce in interface MongoOperationsinputCollectionName - the collection where the map-reduce will read frommapFunction - The JavaScript map functionreduceFunction - The JavaScript reduce functionentityClass - The parametrized type of the returned listpublic <T> MapReduceResults<T> mapReduce(String inputCollectionName, String mapFunction, String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass)
MongoOperationsmapReduce in interface MongoOperationsinputCollectionName - the collection where the map-reduce will read frommapFunction - The JavaScript map functionreduceFunction - The JavaScript reduce functionmapReduceOptions - Options that specify detailed map-reduce behaviorentityClass - The parametrized type of the returned listpublic <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction, Class<T> entityClass)
MongoOperationsmapReduce in interface MongoOperationsquery - The query to use to select the data for the map phaseinputCollectionName - the collection where the map-reduce will read frommapFunction - The JavaScript map functionreduceFunction - The JavaScript reduce functionentityClass - The parametrized type of the returned listpublic <T> MapReduceResults<T> mapReduce(Query query, String inputCollectionName, String mapFunction, String reduceFunction, MapReduceOptions mapReduceOptions, Class<T> entityClass)
MongoOperationsmapReduce in interface MongoOperationsquery - The query to use to select the data for the map phaseinputCollectionName - the collection where the map-reduce will read frommapFunction - The JavaScript map functionreduceFunction - The JavaScript reduce functionmapReduceOptions - Options that specify detailed map-reduce behaviorentityClass - The parametrized type of the returned listpublic <T> GroupByResults<T> group(String inputCollectionName, GroupBy groupBy, Class<T> entityClass)
MongoOperationsgroup in interface MongoOperationsinputCollectionName - the collection where the group operation will read fromgroupBy - the conditions under which the group operation will be performed, e.g. keys, initial document,
reduce function.entityClass - The parametrized type of the returned listpublic <T> GroupByResults<T> group(Criteria criteria, String inputCollectionName, GroupBy groupBy, Class<T> entityClass)
MongoOperationsgroup in interface MongoOperationscriteria - The criteria that restricts the row that are considered for grouping. If not specified all rows are
considered.inputCollectionName - the collection where the group operation will read fromgroupBy - the conditions under which the group operation will be performed, e.g. keys, initial document,
reduce function.entityClass - The parametrized type of the returned listpublic <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, Class<O> outputType)
MongoOperationsaggregate in interface MongoOperationsaggregation - The TypedAggregation specification holding the aggregation operations, must not be
null.outputType - The parametrized type of the returned list, must not be null.public <O> AggregationResults<O> aggregate(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType)
MongoOperationsaggregate in interface MongoOperationsaggregation - The TypedAggregation specification holding the aggregation operations, must not be
null.inputCollectionName - The name of the input collection to use for the aggreation.outputType - The parametrized type of the returned list, must not be null.public <O> AggregationResults<O> aggregate(Aggregation aggregation, Class<?> inputType, Class<O> outputType)
MongoOperationsaggregate in interface MongoOperationsaggregation - The Aggregation specification holding the aggregation operations, must not be
null.inputType - the inputType where the aggregation operation will read from, must not be null or
empty.outputType - The parametrized type of the returned list, must not be null.public <O> AggregationResults<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType)
MongoOperationsaggregate in interface MongoOperationsaggregation - The Aggregation specification holding the aggregation operations, must not be
null.collectionName - the collection where the aggregation operation will read from, must not be null or
empty.outputType - The parametrized type of the returned list, must not be null.public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, String inputCollectionName, Class<O> outputType)
MongoOperationsCursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed. The raw
results will be mapped to the given entity class. The name of the inputCollection is derived from the inputType of
the aggregation.
Aggregation streaming can't be used with aggregation explain. Enabling
explanation mode will throw an IllegalArgumentException.
aggregateStream in interface MongoOperationsaggregation - The TypedAggregation specification holding the aggregation operations, must not be
null.inputCollectionName - The name of the input collection to use for the aggreation.outputType - The parametrized type of the returned list, must not be null.public <O> CloseableIterator<O> aggregateStream(TypedAggregation<?> aggregation, Class<O> outputType)
MongoOperationsCursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed. The raw
results will be mapped to the given entity class and are returned as stream. The name of the inputCollection is
derived from the inputType of the aggregation.
Aggregation streaming can't be used with aggregation explain. Enabling
explanation mode will throw an IllegalArgumentException.aggregateStream in interface MongoOperationsaggregation - The TypedAggregation specification holding the aggregation operations, must not be
null.outputType - The parametrized type of the returned list, must not be null.public <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, Class<?> inputType, Class<O> outputType)
MongoOperationsCursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed. The raw
results will be mapped to the given entity class.
Aggregation streaming can't be used with aggregation explain. Enabling
explanation mode will throw an IllegalArgumentException.aggregateStream in interface MongoOperationsaggregation - The Aggregation specification holding the aggregation operations, must not be
null.inputType - the inputType where the aggregation operation will read from, must not be null or
empty.outputType - The parametrized type of the returned list, must not be null.public <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, String collectionName, Class<O> outputType)
MongoOperationsCursor.
Returns a CloseableIterator that wraps the a Mongo DB Cursor that needs to be closed. The raw
results will be mapped to the given entity class.
Aggregation streaming can't be used with aggregation explain. Enabling
explanation mode will throw an IllegalArgumentException.aggregateStream in interface MongoOperationsaggregation - The Aggregation specification holding the aggregation operations, must not be
null.collectionName - the collection where the aggregation operation will read from, must not be null or
empty.outputType - The parametrized type of the returned list, must not be null.public <T> List<T> findAllAndRemove(Query query, String collectionName)
MongoOperationsMongoOperations.findAllAndRemove(Query, Class, String) to get full type specific support.findAllAndRemove in interface MongoOperationsquery - must not be null.collectionName - must not be null.public <T> List<T> findAllAndRemove(Query query, Class<T> entityClass)
MongoOperationsfindAllAndRemove in interface MongoOperationspublic <T> List<T> findAllAndRemove(Query query, Class<T> entityClass, String collectionName)
MongoOperationsfindAllAndRemove in interface MongoOperationsprotected <T> List<T> doFindAndDelete(String collectionName, Query query, Class<T> entityClass)
query by calling find(Query, Class, String)
and remove(Query, Class, String), whereas the Query for remove(Query, Class, String) is
constructed out of the find result.collectionName - query - entityClass - protected <O> AggregationResults<O> aggregate(Aggregation aggregation, String collectionName, Class<O> outputType, AggregationOperationContext context)
protected <O> CloseableIterator<O> aggregateStream(Aggregation aggregation, String collectionName, Class<O> outputType, AggregationOperationContext context)
public <T> ExecutableFindOperation.ExecutableFind<T> query(Class<T> domainType)
ExecutableFindOperationquery in interface ExecutableFindOperationdomainType - must not be null.ExecutableFindOperation.ExecutableFind.public <T> ExecutableUpdateOperation.ExecutableUpdate<T> update(Class<T> domainType)
ExecutableUpdateOperationupdate in interface ExecutableUpdateOperationdomainType - must not be null.ExecutableUpdateOperation.ExecutableUpdate.public <T> ExecutableRemoveOperation.ExecutableRemove<T> remove(Class<T> domainType)
ExecutableRemoveOperationremove in interface ExecutableRemoveOperationdomainType - must not be null.ExecutableRemoveOperation.ExecutableRemove.public <T> ExecutableAggregationOperation.ExecutableAggregation<T> aggregateAndReturn(Class<T> domainType)
ExecutableAggregationOperationTypedAggregation to specify a potentially different
input type for he aggregation.aggregateAndReturn in interface ExecutableAggregationOperationdomainType - must not be null.ExecutableAggregationOperation.ExecutableAggregation.public <T> ExecutableInsertOperation.ExecutableInsert<T> insert(Class<T> domainType)
ExecutableInsertOperationinsert in interface ExecutableInsertOperationdomainType - must not be null.ExecutableInsertOperation.ExecutableInsert.public Set<String> getCollectionNames()
MongoOperationsgetCollectionNames in interface MongoOperationspublic com.mongodb.client.MongoDatabase getDb()
protected <T> void maybeEmitEvent(MongoMappingEvent<T> event)
protected com.mongodb.client.MongoCollection<org.bson.Document> doCreateCollection(String collectionName, org.bson.Document collectionOptions)
collectionName - collectionOptions - protected <T> T doFindOne(String collectionName, org.bson.Document query, org.bson.Document fields, Class<T> entityClass)
Document and so is the fields specification.collectionName - name of the collection to retrieve the objects from.query - the query document that specifies the criteria used to find a record.fields - the document that specifies the fields to be returned.entityClass - the parameterized type of the returned list.List of converted objects.protected <T> List<T> doFind(String collectionName, org.bson.Document query, org.bson.Document fields, Class<T> entityClass)
collectionName - name of the collection to retrieve the objects fromquery - the query document that specifies the criteria used to find a recordfields - the document that specifies the fields to be returnedentityClass - the parameterized type of the returned list.protected <T> List<T> doFind(String collectionName, org.bson.Document query, org.bson.Document fields, Class<T> entityClass, org.springframework.data.mongodb.core.CursorPreparer preparer)
MongoConverter. The query document is
specified as a standard Document and so is the fields specification.collectionName - name of the collection to retrieve the objects from.query - the query document that specifies the criteria used to find a record.fields - the document that specifies the fields to be returned.entityClass - the parameterized type of the returned list.preparer - allows for customization of the DBCursor used when iterating over the result set, (apply
limits, skips and so on).List of converted objects.protected <S,T> List<T> doFind(String collectionName, org.bson.Document query, org.bson.Document fields, Class<S> entityClass, org.springframework.data.mongodb.core.CursorPreparer preparer, org.springframework.data.mongodb.core.MongoTemplate.DocumentCallback<T> objectCallback)
protected org.bson.Document convertToDocument(CollectionOptions collectionOptions)
protected <T> T doFindAndRemove(String collectionName, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, Collation collation, Class<T> entityClass)
collectionName - name of the collection to retrieve the objects fromquery - the query document that specifies the criteria used to find a recordentityClass - the parameterized type of the returned list.protected <T> T doFindAndModify(String collectionName, org.bson.Document query, org.bson.Document fields, org.bson.Document sort, Class<T> entityClass, Update update, FindAndModifyOptions options)
protected void populateIdIfNecessary(Object savedObject, Object id)
savedObject - id - public PersistenceExceptionTranslator getExceptionTranslator()
public MongoDbFactory getMongoDbFactory()
Copyright © 2011–2017 Pivotal Software, Inc.. All rights reserved.