mongodbperformancemongomapperdatabase

Is it possible to default all MongoDB writes to safe? What is the performance hit from doing this?


For MongoDB 2.2.2, is it possible to default all writes to safe, or do you have to include the right flags for each write operation individually?

If you use safe writes, what is the performance hit?

We're using MongoMapper on Rails.


Solution

  • If you are using the latest version of 10gen official drivers, then the default actually is safe, not fire-and-forget (which used to be the default).

    You can read this blog post by 10gen co-founder and CTO which explains some history and announces that all MongoDB drivers as of late November use "safe" mode by default rather than "fire-and-forget".

    MongoMapper is built on top of 10gen supported Ruby Driver, they also updated their code to be consistent with the new defaults. You can see the check-in and comments here for the master branch. Since I'm not certain what their release schedule is, I would recommend you ask on MongoMapper mailing list.

    Even prior to this change you could set "safe" value on connection level in MongoMapper which is as good as global. Starting with 0.11, you can do it in mongo.yml file. You can see how in the release notes.

    The bottom line is that you don't have to specify safe mode for each write, but you can still specify higher or lower than default durability for each individual write operation if you wish, but when you switch to the latest versions of everything, then you will be using "safe writes" globally by default.