Rails: Store JSON in MongoDB

Boris picture Boris · Oct 30, 2010 · Viewed 8.7k times · Source

I am getting multiple similar JSON object from a remote site and looking to store them in a local MongoDB.

What would be the best way to do this ? (Preferably via Mongoid or Mongo-mapper gems)

Thanks

Answer

mydoghasworms picture mydoghasworms · Jan 18, 2012

You can use a mongoid field of type Hash or an embedded document.

class MyModel
  include Mongoid::Document
  field :some_data, :type => Hash
end