I looked at the mongoid tutorial, but there is none for storing time series data. Also, is there a way to associate ActiveModel with Mongoid.

1

There are 1 best solutions below

0
Dwarknight On

I created the model looking at the documentation. https://www.mongodb.com/docs/mongoid/master/reference/collection-configuration/

The code is as follows:

class Ecg
  include Mongoid::Document
  include Mongoid::Timestamps
  field :voltage, type: Float
  field :timestamp, type: Time
  belongs_to :user


  store_in collection_options: {
    time_series: {
      timeField: "timestamp",
      metaField: "metadata",
      granularity: "milliseconds"
    }
  }
end