Permalink
Browse files

Updating tips for safe mode

  • Loading branch information...
1 parent 49eea35 commit 3697c077603ad2a5cc11f8f7369489000a4d1013 @durran durran committed Jun 30, 2012
Showing with 40 additions and 3 deletions.
  1. +10 −1 en/mongoid/docs/documents.html
  2. +28 −0 en/mongoid/docs/tips.html
  3. +1 −1 en/mongoid/index.html
  4. +1 −1 en/moped/index.html
@@ -273,7 +273,7 @@
values.
</p>
<div class="CodeRay">
- <div class="code"><pre><span class="keyword">class</span> <span class="class">Profile</span>&#x000A; include <span class="constant">Mongoid</span>::<span class="constant">Document</span>&#x000A; field <span class="symbol">:location</span>, type: <span class="constant">Point</span>&#x000A;<span class="keyword">end</span>&#x000A;&#x000A;<span class="keyword">class</span> <span class="class">Point</span>&#x000A;&#x000A; attr_reader <span class="symbol">:x</span>, <span class="symbol">:y</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">initialize</span>(x, y)&#x000A; <span class="instance-variable">@x</span>, <span class="instance-variable">@y</span> = x, y&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">mongoize</span>&#x000A; [ x, y ]&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">class</span> &lt;&lt; <span class="class">self</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">demongoize</span>(object)&#x000A; <span class="constant">Point</span>.new(object[<span class="integer">0</span>], object[<span class="integer">1</span>])&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">evolve</span>(object)&#x000A; <span class="keyword">if</span> object.is_a?(<span class="constant">Point</span>)&#x000A; [ object.x, object.y ]&#x000A; <span class="keyword">else</span>&#x000A; object&#x000A; <span class="keyword">end</span>&#x000A; <span class="keyword">end</span>&#x000A; <span class="keyword">end</span>&#x000A;<span class="keyword">end</span>&#x000A;</pre></div>
+ <div class="code"><pre><span class="keyword">class</span> <span class="class">Profile</span>&#x000A; include <span class="constant">Mongoid</span>::<span class="constant">Document</span>&#x000A; field <span class="symbol">:location</span>, type: <span class="constant">Point</span>&#x000A;<span class="keyword">end</span>&#x000A;&#x000A;<span class="keyword">class</span> <span class="class">Point</span>&#x000A;&#x000A; attr_reader <span class="symbol">:x</span>, <span class="symbol">:y</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">initialize</span>(x, y)&#x000A; <span class="instance-variable">@x</span>, <span class="instance-variable">@y</span> = x, y&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">mongoize</span>&#x000A; [ x, y ]&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">class</span> &lt;&lt; <span class="class">self</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">demongoize</span>(object)&#x000A; <span class="constant">Point</span>.new(object[<span class="integer">0</span>], object[<span class="integer">1</span>])&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">mongoize</span>(object)&#x000A; object&#x000A; <span class="keyword">end</span>&#x000A;&#x000A; <span class="keyword">def</span> <span class="function">evolve</span>(object)&#x000A; <span class="keyword">if</span> object.is_a?(<span class="constant">Point</span>)&#x000A; [ object.x, object.y ]&#x000A; <span class="keyword">else</span>&#x000A; object&#x000A; <span class="keyword">end</span>&#x000A; <span class="keyword">end</span>&#x000A; <span class="keyword">end</span>&#x000A;<span class="keyword">end</span>&#x000A;</pre></div>
</div>
<p>
The instance method <code>mongoize</code> take an instance of your object,
@@ -288,6 +288,15 @@
<code>Point</code> from it.
</p>
<p>
+ The class method <code>mongoize</code> takes an object that you would use
+ to set on your model from your application code, and create the object as
+ it would be stored in the database. This is for cases where you are not
+ passing your model instances of your custom type in the setter:
+ </p>
+ <div class="CodeRay">
+ <div class="code"><pre>point = <span class="constant">Point</span>.new(<span class="integer">12</span>, <span class="integer">24</span>)&#x000A;venue = <span class="constant">Venue</span>.new(location: point) <span class="comment">#=&gt; This uses the mongoize instance method.</span>&#x000A;venue = <span class="constant">Venue</span>.new(location: [ <span class="integer">12</span>, <span class="integer">24</span> ]) <span class="comment">#=&gt; This uses the mongoize class method.</span>&#x000A;</pre></div>
+ </div>
+ <p>
The class method <code>evolve</code> takes an object, and determines how it
is to be transformed for use in criteria. For example we may want to write
a query like so:
View
@@ -85,6 +85,7 @@
<li><a href="#reorder_embedded">Reordering Embedded Docs</a></li>
<li><a href="#gridfs">GridFS</a></li>
<li><a href="#relational_associations">Relational Associations</a></li>
+ <li><a href="#safe_mode">Safe Mode</a></li>
</ul>
</div>
</div>
@@ -210,6 +211,33 @@
the database in an incorrect fashion.
</p>
</section>
+ <section id='safe_mode'>
+ <h2>Safe Mode</h2>
+ <p>
+ By default, safe mode is turned off by default due to that being MongoDB's
+ recommendation. However for users, especially first timers, we recommend
+ that you always have this setting on at least in development and test mode.
+ This will help you understand what is going on with more clarity, instead
+ of jsut making the assumption that your data was actually persisted.
+ </p>
+ <p>
+ To ensure safe mode is on in development and test, you should simply
+ configure this in your <code>mongoid.yml</code>:
+ </p>
+ <div class="CodeRay">
+ <div class="code"><pre><span class="key">development</span>:&#x000A; <span class="key">sessions</span>:&#x000A; <span class="key">default</span>:&#x000A; <span class="key">database</span>: <span class="string"><span class="content">my_app_dev</span></span>&#x000A; <span class="key">hosts</span>:&#x000A; - <span class="string"><span class="content">localhost:27017</span></span>&#x000A; <span class="key">options</span>:&#x000A; <span class="key">safe</span>: <span class="string"><span class="content">true</span></span>&#x000A;<span class="key">test</span>:&#x000A; <span class="key">sessions</span>:&#x000A; <span class="key">default</span>:&#x000A; <span class="key">database</span>: <span class="string"><span class="content">my_app_test</span></span>&#x000A; <span class="key">hosts</span>:&#x000A; - <span class="string"><span class="content">localhost:27017</span></span>&#x000A; <span class="key">options</span>:&#x000A; <span class="key">safe</span>: <span class="string"><span class="content">true</span></span>&#x000A;</pre></div>
+ </div>
+ <p>
+ Also we recommend keeping an eye on the MongoDB logs if you are also getting
+ started, as safe mode itself won't even catch all errors - sometimes MongoDB
+ will simply log an error on the server but send a message back to the client
+ that the operation succeeded.
+ <ul>
+ <li>On OSX (with Homebrew): <code>/usr/local/var/log/mongodb/output.log</code></li>
+ <li>On Ubuntu (with apt-get): <code>/var/log/mongodb/mongodb.log</code></li>
+ </ul>
+ </p>
+ </section>
</div>
</div>
</body>
View
@@ -101,7 +101,7 @@
<tr>
<td class='samurai'><img src="/images/samurai.png" /></td>
<td class='note'>
- Mongoid only supports MRI 1.9.2, 1.9.3, and HEAD, and JRuby 1.6.0+ in
+ Mongoid only supports MRI 1.9.3, and HEAD, and JRuby 1.6.0+ in
1.9 mode. All code samples will use 1.9 syntax.
</td>
</tr>
View
@@ -81,7 +81,7 @@
<tr>
<td class='samurai'><img src="/images/samurai.png" /></td>
<td class='note'>
- Moped only supports MRI 1.9.2, 1.9.3, and HEAD, and JRuby 1.6.0+ in 1.9 mode.
+ Moped only supports MRI 1.9.3, and HEAD, and JRuby 1.6.0+ in 1.9 mode.
All code samples will use 1.9 syntax.
</td>
</tr>

0 comments on commit 3697c07

Please sign in to comment.