I'm trying to define a time-series model in django using mongodb as the backend. I read about some best practices for timeseries data at the MongoDB Blog, and I think I understand it well enough. But now, my problem/question is: how do I define such a model using django's model syntax? I'm not sure if these would be embedded documents
or simply storing arrays
or dicts
in the model field. Here is the suggested mongo format:
ideal mongo document format:
{
timestamp_hour: ISODate("2013-10-10T23:00:00.000Z"),
type: “memory_used”,
values: {
0: { 0: 999999, 1: 999999, …, 59: 1000000 },
1: { 0: 2000000, 1: 2000000, …, 59: 1000000 },
…,
58: { 0: 1600000, 1: 1200000, …, 59: 1100000 },
59: { 0: 1300000, 1: 1400000, …, 59: 1500000 }
}
}
One solution is to do something like this, a document holds a day's worth of data:
# models.py
class timeseries(models.Model):
date = models.DateField(null=True)
value_hour_0 = models.CharField(max_length='1024', blank=True)
value_hour_1 = models.CharField(max_length='1024', blank=True)
value_hour_...
value_hour_23 = models.CharField(max_length='1024', blank=True)
Even if I store arrays
or dicts
in the value_hour_n
field, it doesn't quite offer the advantages of querying the document as mentioned in the article, for example as timeseries.HR.MIN
. Any suggestions?