|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
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).
Method Summary | ||
---|---|---|
boolean |
collectionExists(java.lang.String collectionName)
Check to see if a collection with a given name exists. |
|
DBCollection |
createCollection(java.lang.String collectionName)
Create an uncapped collection with the provided name. |
|
DBCollection |
createCollection(java.lang.String collectionName,
CollectionOptions collectionOptions)
Create a collect with the provided name and options. |
|
void |
dropCollection(java.lang.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(java.lang.String collectionName,
IndexDefinition indexDefinition)
Ensure that an index for the provided IndexDefinition exists. |
|
|
execute(CollectionCallback<T> action)
Executes the given CollectionCallback on the default collection. |
|
|
execute(DbCallback<T> action)
Executes a DbCallback translating any exceptions as necessary. |
|
|
execute(java.lang.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(java.lang.String jsonCommand)
Execute the a MongoDB command expressed as a JSON string. |
|
|
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. |
|
|
find(Query query,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the default MongoDB collection to a List of the specified type. |
|
|
find(Query query,
java.lang.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. |
|
|
find(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass,
CursorPreparer preparer)
Map the results of an ad-hoc query on the specified collection to a List of the specified type. |
|
|
find(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
findAndRemove(Query query,
java.lang.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. |
|
|
findAndRemove(Query query,
java.lang.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. |
|
|
findAndRemove(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
findAndRemove(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
findOne(Query query,
java.lang.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. |
|
|
findOne(Query query,
java.lang.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. |
|
|
findOne(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
findOne(java.lang.String collectionName,
Query query,
java.lang.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. |
|
|
getCollection(java.lang.Class<T> targetClass)
Query for a list of objects of type T from the default collection. |
|
DBCollection |
getCollection(java.lang.String collectionName)
Get a collection by name, creating it if it doesn't exist. |
|
|
getCollection(java.lang.String collectionName,
java.lang.Class<T> targetClass)
Query for a list of objects of type T from the specified collection. |
|
|
getCollection(java.lang.String collectionName,
java.lang.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. |
|
java.util.Set<java.lang.String> |
getCollectionNames()
A set of collection names. |
|
DBCollection |
getDefaultCollection()
The default collection used by this template. |
|
java.lang.String |
getDefaultCollectionName()
The default collection name used by this template. |
|
void |
insert(java.lang.Object objectToSave)
Insert the object into the default collection. |
|
void |
insert(java.lang.String collectionName,
java.lang.Object objectToSave)
Insert the object into the specified collection. |
|
|
insert(java.lang.String collectionName,
T objectToSave,
MongoWriter<T> writer)
Insert the object into the specified collection. |
|
|
insert(T objectToSave,
MongoWriter<T> writer)
Insert the object into the default collection. |
|
void |
insertList(java.util.List<? extends java.lang.Object> listToSave)
Insert a list of objects into the default collection in a single batch write to the database. |
|
|
insertList(java.util.List<? extends T> listToSave,
MongoWriter<T> writer)
Insert a list of objects into the default collection using the provided MongoWriter instance |
|
void |
insertList(java.lang.String collectionName,
java.util.List<? extends java.lang.Object> listToSave)
Insert a list of objects into the specified collection in a single batch write to the database. |
|
|
insertList(java.lang.String collectionName,
java.util.List<? extends T> listToSave,
MongoWriter<T> writer)
Insert a list of objects into the specified collection using the provided MongoWriter instance |
|
void |
remove(java.lang.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. |
|
|
remove(Query query,
java.lang.Class<T> targetClass)
Remove all documents from the default collection that match the provided query document criteria. |
|
void |
remove(java.lang.String collectionName,
Query query)
Remove all documents from the specified collection that match the provided query document criteria. |
|
|
remove(java.lang.String collectionName,
Query query,
java.lang.Class<T> targetClass)
Remove all documents from the specified collection that match the provided query document criteria. |
|
void |
save(java.lang.Object objectToSave)
Save the object to the default collection. |
|
void |
save(java.lang.String collectionName,
java.lang.Object objectToSave)
Save the object to the specified collection. |
|
|
save(java.lang.String collectionName,
T objectToSave,
MongoWriter<T> writer)
Save the object into the specified collection using the provided writer. |
|
|
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(java.lang.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(java.lang.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 |
---|
java.lang.String getDefaultCollectionName()
DBCollection getDefaultCollection()
CommandResult executeCommand(java.lang.String jsonCommand)
jsonCommand
- a MongoDB command expressed as a JSON string.CommandResult executeCommand(DBObject command)
command
- a MongoDB command<T> T execute(DbCallback<T> action)
DbCallback
translating any exceptions as necessary.
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typeaction
- callback object that specifies the MongoDB actions to perform on the passed in DB instance.
<T> T execute(CollectionCallback<T> action)
CollectionCallback
on the default collection.
Allows for returning a result object, that is a domain object or a collection of domain objects.
T
- return typeaction
- callback object that specifies the MongoDB action
<T> T execute(java.lang.String collectionName, CollectionCallback<T> action)
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.
T
- return typecollectionName
- the name of the collection that specifies which DBCollection instance will be passed intoaction
- callback object that specifies the MongoDB action
the callback action.
<T> T executeInSession(DbCallback<T> action)
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.
T
- return typeaction
- callback that specified the MongoDB actions to perform on the DB instance
DBCollection createCollection(java.lang.String collectionName)
collectionName
- name of the collection
DBCollection createCollection(java.lang.String collectionName, CollectionOptions collectionOptions)
collectionName
- name of the collectioncollectionOptions
- options to use when creating the collection.
java.util.Set<java.lang.String> getCollectionNames()
DBCollection getCollection(java.lang.String collectionName)
collectionName
- name of the collection
boolean collectionExists(java.lang.String collectionName)
collectionName
- name of the collection
void dropCollection(java.lang.String collectionName)
collectionName
- name of the collection to drop/delete.<T> java.util.List<T> getCollection(java.lang.Class<T> targetClass)
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.
targetClass
- the parameterized type of the returned list
<T> java.util.List<T> getCollection(java.lang.String collectionName, java.lang.Class<T> targetClass)
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.
collectionName
- name of the collection to retrieve the objects fromtargetClass
- the parameterized type of the returned list.
<T> java.util.List<T> getCollection(java.lang.String collectionName, java.lang.Class<T> targetClass, MongoReader<T> reader)
collectionName
- name of the collection to retrieve the objects fromtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
void ensureIndex(IndexDefinition indexDefinition)
IndexDefinition
exists for the default collection.
If not it will be created.
index
- void ensureIndex(java.lang.String collectionName, IndexDefinition indexDefinition)
IndexDefinition
exists. If not it will be
created.
collectionName
- index
- <T> T findOne(Query query, java.lang.Class<T> targetClass)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> T findOne(Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
<T> T findOne(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> T findOne(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
<T> java.util.List<T> find(Query query, java.lang.Class<T> targetClass)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> java.util.List<T> find(Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
<T> java.util.List<T> find(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> java.util.List<T> find(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
<T> java.util.List<T> find(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass, CursorPreparer preparer)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- 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).
<T> T findAndRemove(Query query, java.lang.Class<T> targetClass)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> T findAndRemove(Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
query
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
<T> T findAndRemove(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.
<T> T findAndRemove(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass, MongoReader<T> reader)
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
.
collectionName
- name of the collection to retrieve the objects fromquery
- the query class that specifies the criteria used to find a record and also an optional fields specificationtargetClass
- the parameterized type of the returned list.reader
- the MongoReader to convert from DBObject to an object.
void insert(java.lang.Object objectToSave)
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.
objectToSave
- the object to store in the collection.void insert(java.lang.String collectionName, java.lang.Object objectToSave)
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.
collectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collection<T> void insert(T objectToSave, MongoWriter<T> writer)
MongoWriter
Insert is used to initially store the object into the
database. To update an existing object use the save method.
T
- the type of the object to insertobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObject<T> void insert(java.lang.String collectionName, T objectToSave, MongoWriter<T> writer)
MongoWriter
Insert is used to initially store the object into the
database. To update an existing object use the save method.
T
- the type of the object to insertcollectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectvoid insertList(java.util.List<? extends java.lang.Object> listToSave)
listToSave
- the list of objects to save.void insertList(java.lang.String collectionName, java.util.List<? extends java.lang.Object> listToSave)
collectionName
- name of the collection to store the object inlistToSave
- the list of objects to save.<T> void insertList(java.util.List<? extends T> listToSave, MongoWriter<T> writer)
T
- the type of object being savedlistToSave
- the list of objects to save.writer
- the writer to convert the object to save into a DBObject<T> void insertList(java.lang.String collectionName, java.util.List<? extends T> listToSave, MongoWriter<T> writer)
T
- the type of object being savedcollectionName
- name of the collection to store the object inlistToSave
- the list of objects to save.writer
- the writer to convert the object to save into a DBObjectvoid save(java.lang.Object objectToSave)
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.
objectToSave
- the object to store in the collectionvoid save(java.lang.String collectionName, java.lang.Object objectToSave)
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.
collectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collection<T> void save(T objectToSave, MongoWriter<T> writer)
MongoWriter
T
- the type of the object to insertobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObject<T> void save(java.lang.String collectionName, T objectToSave, MongoWriter<T> writer)
MongoWriter
T
- the type of the object to insertcollectionName
- name of the collection to store the object inobjectToSave
- the object to store in the collectionwriter
- the writer to convert the object to save into a DBObjectWriteResult updateFirst(Query query, Update update)
queryDoc
- the query document that specifies the criteria used to select a record to be updatedupdateDoc
- the update document that contains the updated object or $ operators to manipulate the
existing object.WriteResult updateFirst(java.lang.String collectionName, Query query, Update update)
collectionName
- name of the collection to update the object inqueryDoc
- the query document that specifies the criteria used to select a record to be updatedupdateDoc
- the update document that contains the updated object or $ operators to manipulate the
existing object.WriteResult updateMulti(Query query, Update update)
queryDoc
- the query document that specifies the criteria used to select a record to be updatedupdateDoc
- the update document that contains the updated object or $ operators to manipulate the
existing object.WriteResult updateMulti(java.lang.String collectionName, Query query, Update update)
collectionName
- name of the collection to update the object inqueryDoc
- the query document that specifies the criteria used to select a record to be updatedupdateDoc
- the update document that contains the updated object or $ operators to manipulate the
existing object.void remove(java.lang.Object object)
object
- void remove(Query query)
queryDoc
- the query document that specifies the criteria used to remove a record<T> void remove(Query query, java.lang.Class<T> targetClass)
T
- query
- targetClass
- void remove(java.lang.String collectionName, Query query)
collectionName
- name of the collection where the objects will removedqueryDoc
- the query document that specifies the criteria used to remove a record<T> void remove(java.lang.String collectionName, Query query, java.lang.Class<T> targetClass)
collectionName
- query
- targetClass
-
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |