Strategies for Real-Time Aggregations in MongoDB

前端 未结 2 1234
眼角桃花
眼角桃花 2021-02-09 08:52

In exploring ways to do real-time analytics with MongoDB, there seems to be a fairly standard way to do sums, but nothing in terms of more complex aggregation. Some things that

相关标签:
2条回答
  • 2021-02-09 09:30

    Could you do some atomic or optimized/real-time operation that grouped the birthdays into something like this?

    It looks like you've added two fields age_rank, average_age. These are effectively calculated fields based on the data you already have. If I gave you the document with page views and user birthdays, it should be really trivial for the client code to find min/max, average, etc.

    It seems to me that you're asking for MongoDB to perform the aggregation for you server-side. But you're adding the limitation that you don't want to use Map/Reduce?

    If I'm understanding your question correctly, you're looking for something where you can say "add this item to an array and have all dependent items update themselves"? You don't want readers to perform any logic, you want everything to happen "magically" on the server side.

    So there are three different ways to tackle this, but only one of them is currently available:

    1. Write this logic client-side. It doesn't sound like the solution you want, but it will work. If you have the underlying data, doing a max/min/med/avg should be pretty trivial in most languages.
    2. Leverage the upcoming features for Aggregation. These are not scheduled until 1.9.x. Improved aggregation will allow to extract the data you're looking for, however, you'll still have to write the appropriate queries. The underlying DB still does not contain the data you're looking for.
    3. You need triggers. If you really want the DB to always consistent and contain summarized data, then this is what you need. However, the triggers feature does not yet exist.

    Unfortunately, your only option right now is #1. Fortunately, I know of several people that are using option #1 successfully.

    0 讨论(0)
  • 2021-02-09 09:50

    There is work planned for the upcoming 1.9.x unstable release that may have aggregations.

    See: https://jira.mongodb.org/browse/SERVER-447

    Of course, it may get bumepd to a later release/

    0 讨论(0)
提交回复
热议问题