Note that there are some explanatory texts on larger screens.

plurals
  1. POAll records disappear in Mongodb/Ruby on Rails/Mongoid Model with hash field attribute and errors
    text
    copied!<p>I was wondering if any anyone else had a similar problem that I have seen - here's what happens;</p> <p>I have a Rails 3.2.14 app using MongoDB and Mongoid I have a model called Selectfield (like a select tag in a form) with an attribute called option_values that is a hash:</p> <pre><code>class Selectfield &lt; Inputfield #inherits name and label from Inputfield field :option_values, type: Hash # key/vals for &lt;option&gt; in &lt;select&gt; end </code></pre> <p>Long story short when I would save a new Selectfield sometimes I would get an error related to the option_values hash, and subsequently it would appear as if all the other records would have been lost. Going to inputfields controller, it would show no records even though I know I had 10+ records saved. This would persist after I fixed the error in the form.</p> <p>What is odd is once I created a new Inputfield without errors, all the previously disappeared records would appear. I would think that this might be related to errors in the formatting of the hash, perhaps a misplaced quotation mark. Perhaps a poorly formatted hash caused the error and a new record would somehow resolve it?</p> <p>While in the short term I have been able to resolve this problem, my biggest concern is how easy it is to corrupt MongoDB to make it appear that all records have been lost. Has anyone seen this problem? I've only been using MongoDB for a week, so I was wondering if this was an issue others had seen. I googled this type of error and did not see anyone with similar problems.</p> <p>Also do I tell either Mongoid or MongoDB? Or do we chalk this up to user error?</p>
 

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