Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails: Store JSON in MongoDB

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

like image 281
Boris Avatar asked Oct 30 '10 10:10

Boris


People also ask

Can you store JSON in MongoDB?

Does MongoDB use BSON or JSON? MongoDB stores data in BSON format both internally, and over the network, but that doesn't mean you can't think of MongoDB as a JSON database. Anything you can represent in JSON can be natively stored in MongoDB, and retrieved just as easily in JSON.

Which database is Best to Store JSON data?

SQL Server and Azure SQL Database have native JSON functions that enable you to parse JSON documents using standard SQL language. You can store JSON documents in SQL Server or SQL Database and query JSON data as in a NoSQL database.

Can Postgres Store JSON?

PostgreSQL offers two types for storing JSON data: json and jsonb . To implement efficient query mechanisms for these data types, PostgreSQL also provides the jsonpath data type described in Section 8.14. 7. The json and jsonb data types accept almost identical sets of values as input.

Is JSON good for storing data?

JSON is a great format to store data, widely used in JavaScript but not only - discover all about it! JSON is a file format that's used to store and interchange data. Data is stored in a set of key-value pairs. This data is human readable, which makes JSON perfect for manual editing.


1 Answers

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

class MyModel
  include Mongoid::Document
  field :some_data, :type => Hash
end
like image 157
mydoghasworms Avatar answered Sep 19 '22 02:09

mydoghasworms