Obtain a session bound instance of SessionScoped binding a new ClientSession
with given sessionOptions to each and every command issued against MongoDB.
public void setWriteConcern(@Nullable
com.mongodb.WriteConcern writeConcern)
Configures the 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.
Execute the a MongoDB command expressed as a JSON string. Parsing is delegated to Document.parse(String) to
obtain the Document holding the actual command. Any errors that result from executing this command will be
converted into Spring's DAO exception hierarchy.
Executes a DbCallback translating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.
Executes the given CollectionCallback 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.
Executes the given CollectionCallback on the collection of the given name.
Allows for returning a result object, that is a domain object or a collection of domain objects.
Obtain a session bound instance of SessionScoped binding a new ClientSession
with given sessionOptions to each and every command issued against MongoDB.
Returns a new BulkOperations for the given collection. NOTE: Any additional support for field mapping, etc. is not available for update or
remove operations in bulk mode due to the lack of domain type information. Use
#bulkOps(BulkMode, Class, String) to get full type specific support.
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.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
type.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Determine result of given Query contains at least one element. NOTE: Any additional support for query/field mapping, etc. is not available due to the lack of
domain type information. Use MongoOperations.exists(Query, Class, String) to get full type specific support.
Map the results of an ad-hoc query on the collection for the entity class to a List of the specified type.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Map the results of an ad-hoc query on the specified collection to a List of the specified type.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Returns a document with the given id mapped onto the given class. The collection the query is ran against will be
derived from the given target class as well.
Returns GeoResults 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.
Returns GeoResults 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.
collectionName - the collection to trigger the query against. If no collection name is given the entity class
will be inspected. Must not be null nor empty.
the converted object that was updated or null, if not found. Depending on the value of
FindAndModifyOptions.isReturnNew() this will either be the object as it was before the update or as
it is after the update.
query - the Query class that specifies the Criteria used to find a record and also an optional
fields specification. Must not be null.
update - the Update to apply on matching documents. Must not be null.
options - the FindAndModifyOptions holding additional information. Must not be null.
entityClass - the parametrized type. Must not be null.
collectionName - the collection to query. Must not be null.
Returns:
the converted object that was updated or null, if not found. Depending on the value of
FindAndModifyOptions.isReturnNew() this will either be the object as it was before the update or as
it is after the update.
Triggers
findOneAndReplace
to replace a single document matching Criteria of given Query with the replacement document
taking FindAndReplaceOptions into account. NOTE: The replacement entity must not hold an id.
query - the Query class that specifies the Criteria used to find a record and also an optional
fields specification. Must not be null.
replacement - the replacement document. Must not be null.
options - the FindAndModifyOptions holding additional information. Must not be null.
entityType - the type used for mapping the Query to domain type fields. Must not be null.
collectionName - the collection to query. Must not be null.
resultType - the parametrized type projection return type. Must not be null, use the domain type of
Object.class instead.
Returns:
the converted object that was updated or null, if not found. Depending on the value of
FindAndReplaceOptions.isReturnNew() this will either be the object as it was before the update or
as it is after the update.
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. The first document that matches the query is returned and also removed from the collection in the
database.
The object is converted from the MongoDB native representation using an instance of MongoConverter.
The query is specified as a Query which can be created either using the BasicQuery or the more
feature rich Query.
Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified
type. The first document that matches the query is returned and also removed from the collection in the database.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Returns the number of documents for the given Query 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.
Insert the object into the collection for the entity type of the object to save.
The object is converted to the MongoDB native representation using an instance of MongoConverter.
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 the object into the specified collection.
The object is converted to the MongoDB native representation using an instance of MongoConverter. 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.
Prepare the collection before any processing is done using it. This allows a convenient way to apply settings like
slaveOk() etc. Can be overridden in sub-classes.
Prepare the WriteConcern before any processing is done using it. This allows a convenient way to apply custom
settings in sub-classes.
In case of using MongoDB Java driver version 3 the returned WriteConcern will be defaulted to
WriteConcern.ACKNOWLEDGED when WriteResultChecking is set to WriteResultChecking.EXCEPTION.
Parameters:
mongoAction - any MongoAction already configured or null
Returns:
The prepared WriteConcern or null
doInsert
protected <T> T doInsert(String collectionName,
T objectToSave,
MongoWriter<T> writer)
Save the object to the collection for the entity type of the object to save. This will perform an insert if the
object is not already present, that is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of MongoConverter. 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 the object to the specified collection. This will perform an insert if the object is not already present, that
is an 'upsert'.
The object is converted to the MongoDB native representation using an instance of MongoConverter. 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.
Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
combining the query document and the update document.
Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
combining the query document and the update document. NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of
domain type information. Use MongoOperations.upsert(Query, Update, Class, String) to get full type specific support.
Performs an upsert. If no document is found that matches the query, a new document is created and inserted by
combining the query document and the update document.
Updates the first object that is found in the specified collection that matches the query document criteria with
the provided updated document. NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of
domain type information. Use MongoOperations.updateFirst(Query, Update, Class, String) to get full type specific support.
Updates all objects that are found in the specified collection that matches the query document criteria with the
provided updated document. NOTE: Any additional support for field mapping, versions, etc. is not available due to the lack of
domain type information. Use MongoOperations.updateMulti(Query, Update, Class, String) to get full type specific support.
Remove all documents from the specified collection that match the provided query document criteria. There is no
conversion/mapping done for any criteria using the id field. NOTE: Any additional support for field mapping is not available due to the lack of domain type
information. Use MongoOperations.remove(Query, Class, String) to get full type specific support.
Remove all documents that match the provided query document criteria from the the collection used to store the
entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.
Remove all documents that match the provided query document criteria from the the collection used to store the
entityClass. The Class parameter is also used to help convert the Id of the object if it is present in the query.
Query for a list of objects of type T from the collection used by the entity class.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Query for a list of objects of type T from the specified collection.
The object is converted from the MongoDB native representation using an instance of MongoConverter. 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.
Execute a group operation over the entire collection. The group operation entity class should match the 'shape' of
the returned object that takes int account the initial document structure as well as any finalize functions.
Execute a group operation restricting the rows to those which match the provided Criteria. The group operation
entity class should match the 'shape' of the returned object that takes int account the initial document structure
as well as any finalize functions.
Execute an aggregation operation. The raw results will be mapped to the given entity class. The name of the
inputCollection is derived from the inputType of the aggregation.
Execute an aggregation operation. The raw results will be mapped to the given entity class. The name of the
inputCollection is derived from the inputType of the aggregation.
Execute an aggregation operation backed by a Mongo DB Cursor.
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.
Execute an aggregation operation backed by a Mongo DB Cursor.
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.
Execute an aggregation operation backed by a Mongo DB Cursor.
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.
Execute an aggregation operation backed by a Mongo DB Cursor.
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.
Returns and removes all documents form the specified collection that match the provided query. NOTE: Any additional support for field mapping is not available due to the lack of domain type
information. Use MongoOperations.findAllAndRemove(Query, Class, String) to get full type specific support.
Returns and removes all documents that match the provided query document criteria from the the collection used to
store the entityClass. The Class parameter is also used to help convert the Id of the object if it is present in
the query.
Start creating an aggregation operation that returns results mapped to the given domain type.
Use TypedAggregation to specify a potentially different
input type for he aggregation.
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
The query document is specified as a standard Document and so is the fields specification.
Parameters:
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.
Map the results of an ad-hoc query on the default MongoDB collection to a List using the template's converter. The
query document is specified as a standard Document and so is the fields specification.
Parameters:
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.
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. The object is
converted from the MongoDB native representation using an instance of MongoConverter. The query document is
specified as a standard Document and so is the fields specification.
Parameters:
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).
Convert given CollectionOptions to a document and take the domain type information into account when
creating a mapped schema for validation.
This method calls convertToDocument(CollectionOptions) for backwards compatibility and potentially
overwrites the validator with the mapped validator document. In the long run
convertToDocument(CollectionOptions) will be removed so that this one becomes the only source of truth.
Parameters:
collectionOptions - can be null.
targetType - must not be null. Use Object type instead.
Map the results of an ad-hoc query on the default MongoDB collection to an object using the template's converter.
The first document that matches the query is returned and also removed from the collection in the database.
The query document is specified as a standard Document and so is the fields specification.
Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query document that specifies the criteria used to find a record
entityClass - the parameterized type of the returned list.