Note that there are some explanatory texts on larger screens.

plurals
  1. POMongoModel gem vs the schemaless database
    primarykey
    data
    text
    <p>I'm using the MongoModel gem in a Ruby on Rails project and it works fine. Works fine as long as you strictly follow the structure defined in your models, so basically using MongoDB as a database with schema. But one of the advantages of MongoDB, well, from a certain perspective, is that it is a schemaless database. And I would like to make use of it, add random fields to documents, just as you can in the mongo shell.</p> <p>How to do that? Is there a way?</p> <p>Update:</p> <p>I'm trying to make it more clear why I am asking this, especially in reply to comments from zero.zero.seven and j03w. It's not because I'm lazy to figure out a structure, it's because I want to make use of this excellent feature, flexibility, of Mongo. </p> <p>I've done a <strong>similar thing</strong> previously on MS SQL and .Net. The structure for a part of the database was defined in an XML file which defined the form and not a table. Values of the form were stored in a vertical structure, like, with the ID of the instance of the current item in question and the ID of the field on the form, all integers went to the "integers" table, strings to the "strings" table. This gave me <strong>flexibility</strong>: if somebody found out that they needed new pieces of information to get their job done, they just had to edit the XML and add new fields in it. They were displayed on the form and stored in the vertical DB structure. But of course it also had its drawbacks: a lot more records, less clear database, table structure not reflecting your information structure. Performance, maybe.</p> <p>Now it is a piece of cake as long as you're playing with this in the Mongo console. But how can you do it in Rails? I'm looking for a solution where you can define structures somewhere else, not in a model. Some fields would be ubiquitous, of course, one of them could be the "subject". So if subjects says "travel", the application would ask you for "destination" and "departure date" and when it says "calendar entry", you would be prompted for "appointment date" and "participants". So there is a structure but that changes from instance to instance, from document to document.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload