I need to create a database of time series, and perform the following tasks:
- create new time series
- update existing time series
- query one or several time series at once (for instance all time series for the same date etc…)
Is Mongo adapted to that and if yes, how should I structure the database? (one time serie = one document? Or one document = one entry of the time serie, and all these documents form the collection which is the entire time series?)
I am a bit lost here and I find it difficult to find any information as usually Mongo is presented as very flexible so the user has the choice in the infrastructure.
Any link to tutorial that specifically explain how to manage time series in Mongo is very much welcome.
Thank you!
Best Answer
I suggest a single time series entry per document. There are some problems with storing multiple entries per document:
Also note a timestamp is built-in to the default MongoDB ObjectId. You can use this if the time series precision is less than one second.
Here is an example BSON document from an event logging library that uses MongoDB:
Since an event log is similar to a time series, it may be worth studying the rest of the code. There are versions in Java, C#, PHP, and Python.
Here is another similar open source project: Zarkov
[update] In response to @RockScience's comment, I've adding some more references: