DATAMONGO-566 - Add support for derived delete-by queries.
Using keywords remove or delete in derived query, or setting @Query(delete=true) removes documents matching the query. If the return type is assignable to Number, the total number of affected documents is returned. In case the return type is collection like the query is executed against the store in first place. All documents included in the resulting collection are deleted in a subsequent call. Additionally findAllAndRemove(…) methods have been added to MongoTemplate. Original pull request: #147.
This commit is contained in:
committed by
Oliver Gierke
parent
70e5efd0d9
commit
ba48290a3e
@@ -394,6 +394,29 @@ public class PersonRepositoryTests {
|
||||
</tgroup>
|
||||
</table></para>
|
||||
|
||||
<section id="mongodb.repositories.queries.delete">
|
||||
<title>Repository delete queries</title>
|
||||
|
||||
<para>The above keywords can be used in conjunciton with
|
||||
<code>delete…By</code> or <code>remove…By</code> to create queries
|
||||
deleting matching documents.</para>
|
||||
|
||||
<example>
|
||||
<title><code>Delete…By</code> Query</title>
|
||||
|
||||
<programlisting language="java">public interface PersonRepository extends MongoRepository<Person, String> {
|
||||
List <Person> deleteByLastname(String lastname);
|
||||
|
||||
Long deletePersonByLastname(String lastname);
|
||||
}</programlisting>
|
||||
</example>
|
||||
|
||||
<para>Using return type <interfacename>List</interfacename> will
|
||||
retrieve and return all matching documents before actually deleting
|
||||
them. A numeric return type directly removes the matching documents
|
||||
returning the total number of documents removed.</para>
|
||||
</section>
|
||||
|
||||
<section id="mongodb.repositories.queries.geo-spatial">
|
||||
<title>Geo-spatial repository queries</title>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user