Skip to content

Commit 3af38a6

Browse files
artembilangaryrussell
authored andcommitted
GH-8779: MongoDbMS Fix distinct result conversion (#8781)
Fixes #8779 The `MongoTemplate` has now a `findDistinct()` API with a smart result conversion instead of native driver plain expectations **Cherry-pick to `6.1.x` & `6.0.x`**
1 parent c7b5453 commit 3af38a6

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/ConfigurableMongoDbMessageStore.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,9 @@ public void completeGroup(Object groupId) {
239239
@Override
240240
public Iterator<MessageGroup> iterator() {
241241
Query query = Query.query(Criteria.where(MessageDocumentFields.GROUP_ID).exists(true));
242-
Iterable<String> groupIds = getMongoTemplate().getCollection(collectionName)
243-
.distinct(MessageDocumentFields.GROUP_ID, query.getQueryObject(), String.class);
242+
Iterable<Object> groupIds =
243+
getMongoTemplate()
244+
.findDistinct(query, MessageDocumentFields.GROUP_ID, this.collectionName, Object.class);
244245

245246
return StreamSupport.stream(groupIds.spliterator(), false)
246247
.map(this::getMessageGroup)

spring-integration-mongodb/src/main/java/org/springframework/integration/mongodb/store/MongoDbMessageStore.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -367,8 +367,7 @@ public Iterator<MessageGroup> iterator() {
367367

368368
Query query = Query.query(Criteria.where(GROUP_ID_KEY).exists(true));
369369

370-
Iterable<String> groupIds = this.template.getCollection(this.collectionName)
371-
.distinct(GROUP_ID_KEY, query.getQueryObject(), String.class);
370+
Iterable<Object> groupIds = this.template.findDistinct(query, GROUP_ID_KEY, this.collectionName, Object.class);
372371

373372
for (Object groupId : groupIds) {
374373
messageGroups.add(getMessageGroup(groupId));

spring-integration-mongodb/src/test/java/org/springframework/integration/mongodb/store/AbstractMongoDbMessageGroupStoreTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ void testMessageGroupIterator() {
374374
Message<?> message = new GenericMessage<>("1");
375375
store2.addMessagesToGroup("1", message);
376376
store1.addMessagesToGroup("2", new GenericMessage<>("2"));
377-
store2.addMessagesToGroup("3", new GenericMessage<>("3"));
377+
store2.addMessagesToGroup(UUID.randomUUID(), new GenericMessage<>("3"));
378378

379379
MessageGroupStore store3 = this.getMessageGroupStore();
380380
Iterator<MessageGroup> iterator = store3.iterator();

0 commit comments

Comments
 (0)