通读文档,我仍然对以流畅的方式使用 mongoClient 的优势(如果有的话)感到困惑。任何人都可以向我解释一下,是否可以保证订单;
在线运行 - 两者将同时运行,不保证顺序。
mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {});
mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {});
嵌套运行 - getSomeCommand1 将在 getSomeCommand2 之前先运行完成。
mongoClient.runCommand("aggregate", getSomeCommand1(), res1 -> {
mongoClient.runCommand("aggregate", getSomeCommand2(), res2 -> {});
});
以流畅的方式运行 - 与排队运行一样吗?
mongoClient.runCommand("aggregate", getSomeCommand1(), res -> {}).mongoClient.runCommand("aggregate", getSomeCommand2(), res -> {});
最佳答案
远非完整的答案,但运行一些基本测试表明以流利的方式运行与排队运行相同;
我在大型数据集上运行了一个慢速命令(聚合)和一个快速命令(计数)。
mongoClient.runCommand("aggregate", getTotalRecsPerTypeCommand(sellerId, collection), res -> {
result.put("totalRecsPerType", res.result());
}).count(collection, new JsonObject().put("sellerId", sellerId), res -> {
result.put("totalRecs", res.result());
requestMessage.reply(result);
});
最初只返回总数,但是当回复从快速命令移动到慢速命令时,两个结果都会返回。这表明它们同时运行,没有顺序保证。
mongoClient.runCommand("aggregate", getTotalRecsPerTypeCommand(sellerId, collection), res -> {
result.put("totalRecsPerType", res.result());
requestMessage.reply(result);
}).count(collection, new JsonObject().put("sellerId", sellerId), res -> {
result.put("totalRecs", res.result());
});
关于java - 流畅地使用 Vertx mongodb 客户端与内联与嵌套,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37119901/