use of com.mongodb.client.model.changestream.ChangeStreamDocument in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method useAggregationToFilterMessages.
// DATAMONGO-1803
@Test
public void useAggregationToFilterMessages() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, User> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<User> request = //
ChangeStreamRequest.builder(messageListener).collection(//
"user").filter(newAggregation(match(//
new Criteria().orOperator(where("user_name").is("huffyFluffy"), where("user_name").is("jellyBelly"))))).build();
Subscription subscription = container.register(request, User.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.save(sugarSplashy);
template.save(huffyFluffy);
awaitMessages(messageListener);
List<User> messageBodies = messageListener.getMessages().stream().map(Message::getBody).collect(Collectors.toList());
assertThat(messageBodies).hasSize(2).doesNotContain(sugarSplashy);
}
use of com.mongodb.client.model.changestream.ChangeStreamDocument in project spring-data-mongodb by spring-projects.
the class ChangeStreamTests method mapsTypedAggregationToFilterMessages.
// DATAMONGO-1803
@Test
public void mapsTypedAggregationToFilterMessages() throws InterruptedException {
CollectingMessageListener<ChangeStreamDocument<Document>, User> messageListener = new CollectingMessageListener<>();
ChangeStreamRequest<User> request = //
ChangeStreamRequest.builder().collection(//
"user").publishTo(//
messageListener).filter(newAggregation(User.class, //
match(new Criteria().orOperator(where("userName").is("huffyFluffy"), where("userName").is("jellyBelly"))))).build();
Subscription subscription = container.register(request, User.class);
awaitSubscription(subscription);
template.save(jellyBelly);
template.save(sugarSplashy);
template.save(huffyFluffy);
awaitMessages(messageListener);
List<User> messageBodies = messageListener.getMessages().stream().map(Message::getBody).collect(Collectors.toList());
assertThat(messageBodies).hasSize(2).doesNotContain(sugarSplashy);
}
Aggregations