如何有效地使用 MongoDB 通过数据透视创建实时分析?

发布于 2024-12-16 19:42:02 字数 292 浏览 2 评论 0原文

因此,我不断获取大量数据,并将其放入 processedData 集合中。数据看起来像:

{
    date: "2011-12-4",
    time: 2243,
    gender: {
        males: 1231,
        females: 322
    },
    age: 32
}

所以我会不断获得很多这样的数据对象。我希望能够看到所有40岁以上的“男性”。由于数据量巨大,这似乎不是一个有效的查询。

有什么建议吗?

So I'm getting a ton of data continuously that's getting put into a processedData collection. The data looks like:

{
    date: "2011-12-4",
    time: 2243,
    gender: {
        males: 1231,
        females: 322
    },
    age: 32
}

So I'll get lots and lots of data objects like this continually. I want to be able to see all "males" that are above 40 years old. This is not an efficient query it seems because of the sheer size of the data.

Any tips?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沫雨熙 2024-12-23 19:42:02

一般来说,你不能。

不过,根据实际需要,可能还有一些捷径。您想要统计所有数据集中的“40 岁以上男性”,还是只统计一天?

1 天:将您的数据拆分为每日集合(processedData-20111121,...),这将有助于您的查询。您还可以缓存此类查询的结果。

整个数据集:预聚合数据。也就是说,在插入新数据条目时,执行如下操作:

db.preaggregated.update({_id : 'male_40'},
     {$set : {gender : 'm', age : 40}, $inc : {count : 1231}},
     true);

同样,如果您事先知道所有查询,则可以预先计算它们(而不保留原始数据)。

它还取决于您如何定义“实时”以及您将拥有的查询负载有多大。在某些情况下,只触发临时映射缩减就可以了。

Generally speaking, you can't.

However, there may be some shortcuts, depending on actual requirements. Do you want to count 'males above 40' across all dataset, or just one day?

1 day: split your data into daily collections (processedData-20111121, ...), this will help your queries. Also you can cache results of such query.

whole dataset: pre-aggregate data. That is, upon insertion of new data entry, do something like this:

db.preaggregated.update({_id : 'male_40'},
     {$set : {gender : 'm', age : 40}, $inc : {count : 1231}},
     true);

Similarly, if you know all your queries beforehand, you can just precalculate them (and not keep raw data).

It also depends on how you define "real-time" and how big a query load you will have. In some cases it is ok to just fire ad-hoc map-reduces.

淡忘如思 2024-12-23 19:42:02

我猜你的目标 GUI 是一个网站?在这种情况下,您正在寻找一种称为彗星的东西。您应该创建一个层来处理所有数据并向您的客户端或事件总线广播新的突变(更多内容见下文)。 Mongo 不支持实时数据,因为它不会在突变时发出任何内容。因此您可以使用任何适合您的数据存储。

根据您使用的语言,您有不同的选项(对于 comet):

  • Socket.io (nodejs) - Javascript
  • Cometd - Java
  • SignalR - C#
  • Libwebsocket - C++

大多数时候您需要事件总线或消息队列来放置突变事件发生。查看 JMS、Redis 或 NServiceBus(取决于您将使用的)。

My guess your target GUI is a website? In that case you are looking for something called comet. You should make a layer which processes all the data and broadcasts new mutations to your client or event bus (more on that below). Mongo doesn't enable real-time data as it doesn't emit anything on an mutation. So you can use any data store which suites you.

Depending on the language you'll use you have different options (for comet):

  • Socket.io (nodejs) - Javascript
  • Cometd - Java
  • SignalR - C#
  • Libwebsocket - C++

Most of the times you'll need an event bus or message queue to put the mutation events on. Take a look at JMS, Redis or NServiceBus (depending on what you'll use).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文