Spring Data Document

org.springframework.data.document.mongodb
Interface MongoOperations

All Known Implementing Classes:
MongoTemplate

public interface MongoOperations

Interface that specifies a basic set of MongoDB operations. Implemented by MongoTemplate. Not often used but a useful option for extensibility and testability (as it can be easily mocked, stubbed, or be the target of a JDK proxy).

Author:
Thomas Risberg, Mark Pollack, Oliver Gierke

Method Summary
 boolean collectionExists(String collectionName)
          Check to see if a collection with a given name exists.
 DBCollection createCollection(String collectionName)
          Create an uncapped collection with the provided name.
 DBCollection createCollection(String collectionName, CollectionOptions collectionOptions)
          Create a collect with the provided name and options.
 void dropCollection(String collectionName)
          Drop the collection with the given name.
 void ensureIndex(IndexDefinition indexDefinition)
          Ensure that an index for the provided IndexDefinition exists for the default collection.
 void ensureIndex(String collectionName, IndexDefinition indexDefinition)
          Ensure that an index for the provided IndexDefinition exists.
<T> T
execute(CollectionCallback<T> action)
          Executes the given CollectionCallback on the default collection.
<T> T
execute(DbCallback<T> action)
          Executes a DbCallback translating any exceptions as necessary.
<T> T
execute(String collectionName, CollectionCallback<T> action)
          Executes the given CollectionCallback on the collection of the given name.
 CommandResult executeCommand(DBObject command)
          Execute a MongoDB command.
 CommandResult executeCommand(String jsonCommand)
          Execute the a MongoDB command expressed as a JSON string.
<T> T
executeInSession(DbCallback<T> action)
          Executes the given DbCallback within the same connection to the database so as to ensure consistency in a write heavy environment where you may read the data that you wrote.
<T> List<T>
find(Query query, Class<T> targetClass)
          Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
<T> List<T>
find(Query query, Class<T> targetClass, MongoReader<T> reader)
          Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type.
<T> List<T>
find(String collectionName, Query query, Class<T> targetClass)
          Map the results of an ad-hoc query on the specified collection to a List of the specified type.
<T> List<T>
find(String collectionName, Query query, Class<T> targetClass, CursorPreparer preparer)
          Map the results of an ad-hoc query on the specified collection to a List of the specified type.
<T> List<T>
find(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
          Map the results of an ad-hoc query on the specified collection to a List of the specified type.
<T> T
findAndRemove(Query query, Class<T> targetClass)
          Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type.
<T> T
findAndRemove(Query query, Class<T> targetClass, MongoReader<T> reader)
          Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type.
<T> T
findAndRemove(String collectionName, Query query, Class<T> targetClass)
          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
findAndRemove(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
          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
findOne(Query query, Class<T> targetClass)
          Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type.
<T> T
findOne(Query query, Class<T> targetClass, MongoReader<T> reader)
          Map the results of an ad-hoc query on the default MongoDB collection to a single instance of an object of the specified type.
<T> T
findOne(String collectionName, Query query, Class<T> targetClass)
          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
findOne(String collectionName, Query query, Class<T> targetClass, MongoReader<T> reader)
          Map the results of an ad-hoc query on the specified collection to a single instance of an object of the specified type.
<T> List<T>
getCollection(Class<T> targetClass)
          Query for a list of objects of type T from the default collection.
 DBCollection getCollection(String collectionName)
          Get a collection by name, creating it if it doesn't exist.
<T> List<T>
getCollection(String collectionName, Class<T> targetClass)
          Query for a list of objects of type T from the specified collection.
<T> List<T>
getCollection(String collectionName, Class<T> targetClass, MongoReader<T> reader)
          Query for a list of objects of type T from the specified collection, mapping the DBObject using the provided MongoReader.
 Set<String> getCollectionNames()
          A set of collection names.
 DBCollection getDefaultCollection()
          The default collection used by this template.
 String getDefaultCollectionName()
          The default collection name used by this template.
 void insert(Object objectToSave)
          Insert the object into the default collection.
 void insert(String collectionName, Object objectToSave)
          Insert the object into the specified collection.
<T> void
insert(String collectionName, T objectToSave, MongoWriter<T> writer)
          Insert the object into the specified collection.
<T> void
insert(T objectToSave, MongoWriter<T> writer)
          Insert the object into the default collection.
 void insertList(List<? extends Object> listToSave)
          Insert a list of objects into the default collection in a single batch write to the database.
<T> void
insertList(List<? extends T> listToSave, MongoWriter<T> writer)
          Insert a list of objects into the default collection using the provided MongoWriter instance
 void insertList(String collectionName, List<? extends Object> listToSave)
          Insert a list of objects into the specified collection in a single batch write to the database.
<T> void
insertList(String collectionName, List<? extends T> listToSave, MongoWriter<T> writer)
          Insert a list of objects into the specified collection using the provided MongoWriter instance
 void remove(Object object)
          Remove the given object from the collection by Id
 void remove(Query query)
          Remove all documents from the default collection that match the provided query document criteria.
<T> void
remove(Query query, Class<T> targetClass)
          Remove all documents from the default collection that match the provided query document criteria.
 void remove(String collectionName, Query query)
          Remove all documents from the specified collection that match the provided query document criteria.
<T> void
remove(String collectionName, Query query, Class<T> targetClass)
          Remove all documents from the specified collection that match the provided query document criteria.
 void save(Object objectToSave)
          Save the object to the default collection.
 void save(String collectionName, Object objectToSave)
          Save the object to the specified collection.
<T> void
save(String collectionName, T objectToSave, MongoWriter<T> writer)
          Save the object into the specified collection using the provided writer.
<T> void
save(T objectToSave, MongoWriter<T> writer)
          Save the object into the default collection using the provided writer.
 WriteResult updateFirst(Query query, Update update)
          Updates the first object that is found in the default collection that matches the query document with the provided updated document.
 WriteResult updateFirst(String collectionName, Query query, Update update)
          Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.
 WriteResult updateMulti(Query query, Update update)
          Updates all objects that are found in the default collection that matches the query document criteria with the provided updated document.
 WriteResult updateMulti(String collectionName, Query query, Update update)
          Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.
 

Method Detail

getDefaultCollectionName

String getDefaultCollectionName()
The default collection name used by this template.

Returns:

getDefaultCollection

DBCollection getDefaultCollection()
The default collection used by this template.

Returns:
The default collection used by this template

executeCommand

CommandResult executeCommand(String jsonCommand)
Execute the a MongoDB command expressed as a JSON string. This will call the method JSON.parse that is part of the MongoDB driver to convert the JSON string to a DBObject. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.

Parameters:
jsonCommand - a MongoDB command expressed as a JSON string.

executeCommand

CommandResult executeCommand(DBObject command)
Execute a MongoDB command. Any errors that result from executing this command will be converted into Spring's DAO exception hierarchy.

Parameters:
command - a MongoDB command

execute

<T> T execute(DbCallback<T> action)
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.

Type Parameters:
T - return type
Parameters:
action - callback object that specifies the MongoDB actions to perform on the passed in DB instance.
Returns:
a result object returned by the action or null

execute

<T> T execute(CollectionCallback<T> action)
Executes the given CollectionCallback on the default collection.

Allows for returning a result object, that is a domain object or a collection of domain objects.

Type Parameters:
T - return type
Parameters:
action - callback object that specifies the MongoDB action
Returns:
a result object returned by the action or null

execute

<T> T execute(String collectionName,
              CollectionCallback<T> action)
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.

Type Parameters:
T - return type
Parameters:
collectionName - the name of the collection that specifies which DBCollection instance will be passed into
action - callback object that specifies the MongoDB action the callback action.
Returns:
a result object returned by the action or null

executeInSession

<T> T executeInSession(DbCallback<T> action)
Executes the given DbCallback within the same connection to the database so as to ensure consistency in a write heavy environment where you may read the data that you wrote. See the comments on Java Driver Concurrency

Allows for returning a result object, that is a domain object or a collection of domain objects.

Type Parameters:
T - return type
Parameters:
action - callback that specified the MongoDB actions to perform on the DB instance
Returns:
a result object returned by the action or null

createCollection

DBCollection createCollection(String collectionName)
Create an uncapped collection with the provided name.

Parameters:
collectionName - name of the collection
Returns:
the created collection

createCollection

DBCollection createCollection(String collectionName,
                              CollectionOptions collectionOptions)
Create a collect with the provided name and options.

Parameters:
collectionName - name of the collection
collectionOptions - options to use when creating the collection.
Returns:
the created collection

getCollectionNames

Set<String> getCollectionNames()
A set of collection names.

Returns:
list of collection names

getCollection

DBCollection getCollection(String collectionName)
Get a collection by name, creating it if it doesn't exist.

Translate any exceptions as necessary.

Parameters:
collectionName - name of the collection
Returns:
an existing collection or a newly created one.

collectionExists

boolean collectionExists(String collectionName)
Check to see if a collection with a given name exists.

Translate any exceptions as necessary.

Parameters:
collectionName - name of the collection
Returns:
true if a collection with the given name is found, false otherwise.

dropCollection

void dropCollection(String collectionName)
Drop the collection with the given name.

Translate any exceptions as necessary.

Parameters:
collectionName - name of the collection to drop/delete.

getCollection

<T> List<T> getCollection(Class<T> targetClass)
Query for a list of objects of type T from the default collection.

The object is converted from the MongoDB native representation using an instance of MongoConverter. Unless configured otherwise, an instance of SimpleMongoConverter 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.

Parameters:
targetClass - the parameterized type of the returned list
Returns:
the converted collection

getCollection

<T> List<T> getCollection(String collectionName,
                          Class<T> targetClass)
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 SimpleMongoConverter 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.

Parameters:
collectionName - name of the collection to retrieve the objects from
targetClass - the parameterized type of the returned list.
Returns:
the converted collection

getCollection

<T> List<T> getCollection(String collectionName,
                          Class<T> targetClass,
                          MongoReader<T> reader)
Query for a list of objects of type T from the specified collection, mapping the DBObject using the provided MongoReader.

Parameters:
collectionName - name of the collection to retrieve the objects from
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the converted collection

ensureIndex

void ensureIndex(IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists for the default collection. If not it will be created.

Parameters:
index -

ensureIndex

void ensureIndex(String collectionName,
                 IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists. If not it will be created.

Parameters:
collectionName -
index -

findOne

<T> T findOne(Query query,
              Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB 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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the converted object

findOne

<T> T findOne(Query query,
              Class<T> targetClass,
              MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB 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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the converted object

findOne

<T> T findOne(String collectionName,
              Query query,
              Class<T> targetClass)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the converted object

findOne

<T> T findOne(String collectionName,
              Query query,
              Class<T> targetClass,
              MongoReader<T> reader)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the converted object

find

<T> List<T> find(Query query,
                 Class<T> targetClass)
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. Unless configured otherwise, an instance of SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the List of converted objects

find

<T> List<T> find(Query query,
                 Class<T> targetClass,
                 MongoReader<T> reader)
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. Unless configured otherwise, an instance of SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the List of converted objects

find

<T> List<T> find(String collectionName,
                 Query query,
                 Class<T> targetClass)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the List of converted objects

find

<T> List<T> find(String collectionName,
                 Query query,
                 Class<T> targetClass,
                 MongoReader<T> reader)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the List of converted objects

find

<T> List<T> find(String collectionName,
                 Query query,
                 Class<T> targetClass,
                 CursorPreparer preparer)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - 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).
Returns:
the List of converted objects.

findAndRemove

<T> T findAndRemove(Query query,
                    Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB 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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the converted object

findAndRemove

<T> T findAndRemove(Query query,
                    Class<T> targetClass,
                    MongoReader<T> reader)
Map the results of an ad-hoc query on the default MongoDB 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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the converted object

findAndRemove

<T> T findAndRemove(String collectionName,
                    Query query,
                    Class<T> targetClass)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
Returns:
the converted object

findAndRemove

<T> T findAndRemove(String collectionName,
                    Query query,
                    Class<T> targetClass,
                    MongoReader<T> reader)
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 SimpleMongoConverter will be used.

The query is specified as a Query which can be created either using the BasicQuery or the more feature rich Query.

Parameters:
collectionName - name of the collection to retrieve the objects from
query - the query class that specifies the criteria used to find a record and also an optional fields specification
targetClass - the parameterized type of the returned list.
reader - the MongoReader to convert from DBObject to an object.
Returns:
the converted object

insert

void insert(Object objectToSave)
Insert the object into the default collection.

The object is converted to the MongoDB native representation using an instance of MongoConverter. Unless configured otherwise, an instance of SimpleMongoConverter 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 Spring 3.0's new Type Conversion API. See Spring 3 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.

Parameters:
objectToSave - the object to store in the collection.

insert

void insert(String collectionName,
            Object objectToSave)
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 SimpleMongoConverter will be used.

Insert is used to initially store the object into the database. To update an existing object use the save method.

Parameters:
collectionName - name of the collection to store the object in
objectToSave - the object to store in the collection

insert

<T> void insert(T objectToSave,
                MongoWriter<T> writer)
Insert the object into the default collection.

The object is converted to the MongoDB native representation using an instance of MongoWriter

Insert is used to initially store the object into the database. To update an existing object use the save method.

Type Parameters:
T - the type of the object to insert
Parameters:
objectToSave - the object to store in the collection
writer - the writer to convert the object to save into a DBObject

insert

<T> void insert(String collectionName,
                T objectToSave,
                MongoWriter<T> writer)
Insert the object into the specified collection.

The object is converted to the MongoDB native representation using an instance of MongoWriter

Insert is used to initially store the object into the database. To update an existing object use the save method.

Type Parameters:
T - the type of the object to insert
Parameters:
collectionName - name of the collection to store the object in
objectToSave - the object to store in the collection
writer - the writer to convert the object to save into a DBObject

insertList

void insertList(List<? extends Object> listToSave)
Insert a list of objects into the default collection in a single batch write to the database.

Parameters:
listToSave - the list of objects to save.

insertList

void insertList(String collectionName,
                List<? extends Object> listToSave)
Insert a list of objects into the specified collection in a single batch write to the database.

Parameters:
collectionName - name of the collection to store the object in
listToSave - the list of objects to save.

insertList

<T> void insertList(List<? extends T> listToSave,
                    MongoWriter<T> writer)
Insert a list of objects into the default collection using the provided MongoWriter instance

Type Parameters:
T - the type of object being saved
Parameters:
listToSave - the list of objects to save.
writer - the writer to convert the object to save into a DBObject

insertList

<T> void insertList(String collectionName,
                    List<? extends T> listToSave,
                    MongoWriter<T> writer)
Insert a list of objects into the specified collection using the provided MongoWriter instance

Type Parameters:
T - the type of object being saved
Parameters:
collectionName - name of the collection to store the object in
listToSave - the list of objects to save.
writer - the writer to convert the object to save into a DBObject

save

void save(Object objectToSave)
Save the object to the default 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 SimpleMongoConverter 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 Spring 3.0's new Type Conversion API. See Spring 3 Type Conversion" for more details.

Parameters:
objectToSave - the object to store in the collection

save

void save(String collectionName,
          Object objectToSave)
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 SimpleMongoConverter 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 Spring 3.0's new Type Cobnversion API. See Spring 3 Type Conversion" for more details.

Parameters:
collectionName - name of the collection to store the object in
objectToSave - the object to store in the collection

save

<T> void save(T objectToSave,
              MongoWriter<T> writer)
Save the object into the default collection using the provided writer. 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 MongoWriter

Type Parameters:
T - the type of the object to insert
Parameters:
objectToSave - the object to store in the collection
writer - the writer to convert the object to save into a DBObject

save

<T> void save(String collectionName,
              T objectToSave,
              MongoWriter<T> writer)
Save the object into the specified collection using the provided writer. 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 MongoWriter

Type Parameters:
T - the type of the object to insert
Parameters:
collectionName - name of the collection to store the object in
objectToSave - the object to store in the collection
writer - the writer to convert the object to save into a DBObject

updateFirst

WriteResult updateFirst(Query query,
                        Update update)
Updates the first object that is found in the default collection that matches the query document with the provided updated document.

Parameters:
queryDoc - the query document that specifies the criteria used to select a record to be updated
updateDoc - the update document that contains the updated object or $ operators to manipulate the existing object.

updateFirst

WriteResult updateFirst(String collectionName,
                        Query query,
                        Update update)
Updates the first object that is found in the specified collection that matches the query document criteria with the provided updated document.

Parameters:
collectionName - name of the collection to update the object in
queryDoc - the query document that specifies the criteria used to select a record to be updated
updateDoc - the update document that contains the updated object or $ operators to manipulate the existing object.

updateMulti

WriteResult updateMulti(Query query,
                        Update update)
Updates all objects that are found in the default collection that matches the query document criteria with the provided updated document.

Parameters:
queryDoc - the query document that specifies the criteria used to select a record to be updated
updateDoc - the update document that contains the updated object or $ operators to manipulate the existing object.

updateMulti

WriteResult updateMulti(String collectionName,
                        Query query,
                        Update update)
Updates all objects that are found in the specified collection that matches the query document criteria with the provided updated document.

Parameters:
collectionName - name of the collection to update the object in
queryDoc - the query document that specifies the criteria used to select a record to be updated
updateDoc - the update document that contains the updated object or $ operators to manipulate the existing object.

remove

void remove(Object object)
Remove the given object from the collection by Id

Parameters:
object -

remove

void remove(Query query)
Remove all documents from the default collection that match the provided query document criteria.

Parameters:
queryDoc - the query document that specifies the criteria used to remove a record

remove

<T> void remove(Query query,
                Class<T> targetClass)
Remove all documents from the default collection that match the provided query document criteria. The Class parameter is used to help convert the Id of the object if it is present in the query.

Type Parameters:
T -
Parameters:
query -
targetClass -

remove

void remove(String collectionName,
            Query query)
Remove all documents from the specified collection that match the provided query document criteria.

Parameters:
collectionName - name of the collection where the objects will removed
queryDoc - the query document that specifies the criteria used to remove a record

remove

<T> void remove(String collectionName,
                Query query,
                Class<T> targetClass)
Remove all documents from the specified collection that match the provided query document criteria. The Class parameter is used to help convert the Id of the object if it is present in the query.

Parameters:
collectionName -
query -
targetClass -

Spring Data Document

Copyright © 2011. All Rights Reserved.