Java 如何在spring中使用change stream侦听多个集合

Java 如何在spring中使用change stream侦听多个集合,java,mongodb,spring-boot,Java,Mongodb,Spring Boot,我想从一号集合、二号集合、三号集合收集数据,我该怎么做 ChangeStreamRequest request = ChangeStreamRequest.builder().collation(Collation.of("collection_one")) .filter(Aggregation.newAggregation(match(where("operationType").exists(true)))) .publishT

我想从一号集合、二号集合、三号集合收集数据,我该怎么做

       ChangeStreamRequest request = ChangeStreamRequest.builder().collation(Collation.of("collection_one"))
            .filter(Aggregation.newAggregation(match(where("operationType").exists(true))))
            .publishTo(krakenDtoMessageListener)
            .build();
    container.register(request, CollectionOne.class);

我应该创建多个changeStreamRequest还是一个就可以了?

无法监视多个集合。根据mongoDB文档,有3个选项。有关详细信息,请查看特定集合、数据库或部署(所有数据库)

无法查看多个集合。根据mongoDB文档,有3个选项。查看特定集合、查看数据库或查看部署(所有数据库)以了解更多详细信息

在配置更改流时,您可以在集合上指定筛选器

检查下面的java代码

List<Bson> pipeline = singletonList(Aggregates.match(
    Filters.in("ns.coll", asList("coll1", "coll2", "coll3"))
));

MongoCursor<ChangeStreamDocument<Document>> cursor = db.watch(pipeline).fullDocument(FullDocument.UPDATE_LOOKUP).iterator();
List pipeline=singletonList(Aggregates.match(
Filters.in(“ns.coll”,asList(“coll1”、“coll2”、“coll3”))
));
MongoCursor=db.watch(pipeline).fullDocument(fullDocument.UPDATE_LOOKUP).iterator();

您可以使用spring框架编写类似的管道。

在配置变更流时,您可以在集合上指定筛选器

检查下面的java代码

List<Bson> pipeline = singletonList(Aggregates.match(
    Filters.in("ns.coll", asList("coll1", "coll2", "coll3"))
));

MongoCursor<ChangeStreamDocument<Document>> cursor = db.watch(pipeline).fullDocument(FullDocument.UPDATE_LOOKUP).iterator();
List pipeline=singletonList(Aggregates.match(
Filters.in(“ns.coll”,asList(“coll1”、“coll2”、“coll3”))
));
MongoCursor=db.watch(pipeline).fullDocument(fullDocument.UPDATE_LOOKUP).iterator();
您可以使用spring框架编写类似的管道