Spring webflux ReactiveMongoOperations 通过 elemMatch 找到 [英] Spring webflux ReactiveMongoOperations find by elemMatch

查看:73
本文介绍了Spring webflux ReactiveMongoOperations 通过 elemMatch 找到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的集合:

{"type": "bbb", "category": "aaa", "from": "eee", "INTERLOCUTOR": ["test1", "test2"]}

我想找到INTERLOCUTORtest1ReactiveMongoOperations 如何使用?

and I want to find INTERLOCUTOR have test1 ; how to use by ReactiveMongoOperations?

推荐答案

使用 ReactiveMongoOperations 并处理返回的 reactor.core.publisher.Flux 打印查询返回的文档:

Using ReactiveMongoOperations and processing the returned reactor.core.publisher.Flux to print the query returned documents:

ReactiveMongoOperations ops = new ReactiveMongoTemplate(MongoClients.create(), "test");
Criteria c = Criteria.where("INTERLOCUTOR").is("test1");
Query qry = new Query(c);

Flux<Document> flux = ops.find(qry, Document.class, "coll")
flux.subscribe(doc -> System.out.println(doc), throwable -> throwable.printStackTrace());

注意查询实际上是在 subscribe 方法运行时执行的.由于订阅作为异步操作运行,当您运行此操作时,将以下内容添加到当前线程(用于阻止它直到异步操作完成).

Note the query actually executes when the subscribe method runs. Since the subscribe runs as an asynchronous operation, when you run this add the following to the current thread (for blocking it until the async operation completes).

try {
  Thread.sleep(1000);
} catch(InterruptedException e ) {}

这篇关于Spring webflux ReactiveMongoOperations 通过 elemMatch 找到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆