'MongoDB scheme collection for monitoring sensors

I'm designing a monitoring application and hesitating about mongodb scheme. The app will monitoring 32 sensors. Each sensors will have multiple scalar value, but that not the same between sensors (could be differents units, config etc..). Scalar data will be pushed every minute. And for each sensors, there will be one or some array (3200 value) to be pushed too. Each sensors could have a completly different config, that have to be stored too (config is complex, but does not change often at all) and of course event log. I don't know if i have to create different collection for each sensors, with a flat db like :

  • Config
  • 1D_data
  • 2D_data
  • event_log

Or creating sub collection for each sensors with config/1d/2d in each of them.

Request to display data will be "display all 1D from one sensor" (to display a trend over time) and "show a 2D_data at this time".

If it was only scalar value i'll chose the first solution, but dunno if 2D "big" results is also on the game. Thanks for your advices !



Solution 1:[1]

It seems a little oversimplified at first but all the information can be stored in a single collection. There is no added value in having 32 different collections. Each document will have a shape similar to this:

    {
      "device":"D1",
      "created": ISODate("2017-10-02T13:59:48.194Z"),
      "moreCommonMetadata": { whatever: 77 },
      "data": {
        "color":"red",
        "maxAmps":10,
        "maxVolts":240
      }
    },
  {
      "device":"D2",
      "created": ISODate("2017-10-02T13:59:48.194Z"),
      "moreCommonMetadata": { whatever: 77 },
      "data": {
        "bigArray":[23,34,45,56,7,78,78,78],
        "adj": [{foo:'bar', bin:'baz'}, {corn:'dog'}],
        "vers": 2
      }
    }

Queries can easily sweep across the metadata, and the data field can be any shape and will be logically tied to the device field i.e. some value of the device field will drive logic to manipulate the data field.

A fairly comprehensive example can be found at http://moschetti.org/rants/lhs.html

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1