How to create a mongoid model for timeseries (ECG) data in rails? The user model is normal database table, user has many ECGs

43 views Asked by At

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 answers

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