Skip to content

Commit 3d705a7

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 996c57b commit 3d705a7

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
@@ -418,7 +418,7 @@ Object execute(Query query) {
418418
private Object deleteAndConvertResult(Query query, MongoEntityMetadata<?> metadata) {
419419

420420
if (method.isCollectionQuery()) {
421-
return operations.findAllAndRemove(query, metadata.getJavaType());
421+
return operations.findAllAndRemove(query, metadata.getJavaType(), metadata.getCollectionName());
422422
}
423423

424424
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
@@ -101,6 +101,7 @@ public void testDeleteExecutionCallsRemoveCorreclty() {
101101

102102
/**
103103
* @see DATAMONGO-566
104+
* @see DATAMONGO-1040
104105
*/
105106
@SuppressWarnings("unchecked")
106107
@Test
@@ -111,7 +112,8 @@ public void testDeleteExecutionLoadsListOfRemovedDocumentsWhenReturnTypeIsCollec
111112

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

114-
verify(this.mongoOperationsMock, times(1)).findAllAndRemove(Matchers.any(Query.class), Matchers.eq(Person.class));
115+
verify(this.mongoOperationsMock, times(1)).findAllAndRemove(Matchers.any(Query.class), Matchers.eq(Person.class),
116+
Matchers.eq("persons"));
115117
}
116118

117119
/**

0 commit comments

Comments
 (0)