In my app i want to combine 2 change streams to listen to changes to some filter object and to the inserts/deletes to the collection which is actually in question (to which i apply the filter residing in a different collection)
Therefore i have an approximate code like this:
public Flux<List<Object>> findAll(String userId){
<some code here>
return service.findByUserId(userId).
< here i get initial set of data when change streams do not act >
.concatWith(reactiveMongoTemplate
.changeStream("Filter",options,Filter.class)
< here i listen to changes to the filter >
)
.concatWith(reactiveMongoTemplate
.changeStream("Object",options,Object.class)
< here i listen to changes to the collection itself >
);
}
The problem is - second change stream is not working. This i can tell by switching them - as i switch the higher concatWith
works and the one which goes below does not.
The question
Have you faced with such behavior?
What could be a better approach to do some complex listening on 2+ collections to deliver to the UI these changes?
Update
This is the whole method i have - with one changeStream working and another one not:
public Flux<List<EventDTO>> findAll(String userId){
Aggregation fluxAggregation = changeStreamHelper.createAggregationBasedOnUserId(userId);
ChangeStreamOptions options = changeStreamHelper.createChangeStreamOpts(fluxAggregation);
return eventListFilterService.findEventListFilterByUserId(userId).flatMap(fltr -> Mono.just(activeEventsFilter.applyCriterion(null, fltr))
.flatMap(criteria -> eventFilteredRepository.findEventsByCriteria(criteria)
.flatMap(eventMapper::toDto).collectList()))
.concatWith(reactiveMongoTemplate
.changeStream("EventListFilter", options, EventListFilter.class).map(ChangeStreamEvent::getBody)
.map(fltr -> activeEventsFilter.applyCriterion(null, fltr))
.flatMap(criteria -> eventFilteredRepository.findEventsByCriteria(criteria)
.flatMap(eventMapper::toDto).collectList())
)
.concatWith(reactiveMongoTemplate
.changeStream("Event", changeStreamHelper.createSimpleChangeStreamOpts(), Event.class).map(ChangeStreamEvent::getBody)
.flatMap(event -> eventListFilterService.findEventListFilterByUserId(userId).flatMap(fltr -> Mono.just(activeEventsFilter.applyCriterion(null, fltr))
.flatMap(criteria -> eventFilteredRepository.findEventsByCriteria(criteria)
.flatMap(eventMapper::toDto).collectList())
)));
}