Skip to content

Commit 8bb62a6

Browse files
christophstroblodrotbohm
authored andcommitted
DATAMONGO-1040 - Derived delete should respect collection name.
Adding collection metadata allows to fine grained remove entities from specific collections using derived delete queries. Original pull request: #223.
1 parent d6defbc commit 8bb62a6

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

spring-data-mongodb/src/main/java/org/springframework/data/mongodb/repository/query/AbstractMongoQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ Object execute(Query query) {
388388
private Object deleteAndConvertResult(Query query, MongoEntityMetadata<?> metadata) {
389389

390390
if (method.isCollectionQuery()) {
391-
return operations.findAllAndRemove(query, metadata.getJavaType());
391+
return operations.findAllAndRemove(query, metadata.getJavaType(), metadata.getCollectionName());
392392
}
393393

394394
WriteResult writeResult = operations.remove(query, metadata.getJavaType(), metadata.getCollectionName());

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/repository/query/AbstractMongoQueryUnitTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ public void testDeleteExecutionCallsRemoveCorreclty() {
9696

9797
/**
9898
* @see DATAMONGO-566
99+
* @see DATAMONGO-1040
99100
*/
100101
@SuppressWarnings("unchecked")
101102
@Test
@@ -106,7 +107,8 @@ public void testDeleteExecutionLoadsListOfRemovedDocumentsWhenReturnTypeIsCollec
106107

107108
createQueryForMethod("deleteByLastname", String.class).setDeleteQuery(true).execute(new Object[] { "booh" });
108109

109-
verify(this.mongoOperationsMock, times(1)).findAllAndRemove(Matchers.any(Query.class), Matchers.eq(Person.class));
110+
verify(this.mongoOperationsMock, times(1)).findAllAndRemove(Matchers.any(Query.class), Matchers.eq(Person.class),
111+
Matchers.eq("persons"));
110112
}
111113

112114
/**

0 commit comments

Comments
 (0)