1

我有一个这样的集合:

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

我想找到INTERLOCUTORtest1ReactiveMongoOperations如何使用?

4

2 回答 2

2

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

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方法运行时实际执行。由于订阅作为异步操作运行,因此当您运行此操作时,将以下内容添加到当前线程(用于阻止它直到异步操作完成)。

try {
  Thread.sleep(1000);
} catch(InterruptedException e ) {}
于 2020-10-05T11:37:27.543 回答
2
db.collection.find({"INTERLOCUTOR" : "test1"})
于 2020-10-05T10:09:50.947 回答