如何从 eventBus vertx2 中 mongo 的多个集合的多个查询中获取结果?

How to get result from multiple query on multiple collection of mongo in eventBus vertx2?

我正在努力提供 API,我正在按月存储数据到数据库,按日期存储数据到 mongodb。

所以我有 db db_08_2015 然后我有从 date_01date_31 的 31 个集合 我必须查询从日期 1 到日期 10 的数据以获得总支出所以我需要像这样发送 31 个请求。

我的问题是在我 return 向客户端同步请求到 mongo 以获得结果之前,如何通过 1 个请求获取数据以获得总和。 就像我有 date_01 = 10 然后 date_02 = 20 ... 我想在 return 之前将所有内容加起来给客户。

vertx.eventBus().send("mongodb-persistor", json, new Handler<Message<JsonObject>>() {
                @Override
                public void handle(Message<JsonObject> message) {
                    logger.info(message.body());
                    JsonObject result = new JsonObject(message.body().encodePrettily());
                    JsonArray r = result.getArray("results");
                    if (r.isArray()) {
                        if (r.size() > 0) {
                            String out = r.get(0).toString();
                            req.response().end(out);
                        } else {
                            req.response().end("{}");
                        }
                    } else {
                        req.response().end(message.body().encodePrettily());
                    }
                }
            });

我认为在您的情况下,采用不同的数据建模方法可能会更好。 在分析方面,我会推荐以下引用的 lambda 架构方法:

  • All data entering the system is dispatched to both the batch layer and the speed layer for processing.
  • The batch layer has two functions: (i) managing the master dataset (an immutable, append-only set of raw data), and (ii) to pre-compute the batch views.
  • The serving layer indexes the batch views so that they can be queried in low-latency, ad-hoc way.
  • The speed layer compensates for the high latency of updates to the serving layer and deals with recent data only.
  • Any incoming query can be answered by merging results from batch views and real-time views.

考虑到上述情况,为什么不拥有一个聚合集合来以您的查询所需的格式保存聚合数据,同时以您描述的格式保留原始副本。

有了这个,您将能够以所需的查询格式查看数据,并在系统出现问题时重新创建聚合数据。

图表和引用的参考 - Lambda Architecture