Eric Xiong
Eric Xiong

Reputation: 11

How can I efficiently store rapidly changing time-series data in mongodb?

I have live time-series data generated by a light sensor, and presented as a rapidly changing (refreshing about every 20 milliseconds) variable in the public javascript file. How can I store them into mongo efficiently? Could anybody give me some suggestions about the best practices?

Upvotes: 0

Views: 1151

Answers (1)

Sam Hiatt
Sam Hiatt

Reputation: 395

This sounds like a good case for using mongodb's Capped Collections.

Capped collections are fixed-size collections that support high-throughput operations that insert and retrieve documents based on insertion order. Capped collections work in a way similar to circular buffers: once a collection fills its allocated space, it makes room for new documents by overwriting the oldest documents in the collection.

You could insert each light sensor measurement as a new document in a Capped Collection, then you can efficiently retrieve the measurements in the same order as they were inserted, and also not have to worry about running out of storage space.

Upvotes: 1

Related Questions