O'Reilly logo

Learning Mongoid by Gautam Rege

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Persisting Documents

Till now we have seen why Mongoid is so awesome and what documents are. In this chapter we will see how the documents are persisted on the disk. Some details we will learn about are as follows:

  • The various options to save documents
  • The compliance of ActiveModel with callbacks and validations
  • Nested attributes in Mongoid
  • Atomic persistence

MongoDB persistence strategy

MongoDB saves data in memory-mapped files so that data access is faster than direct disk I/O. When some document is saved, it is written quickly to the memory and persisted to the disk lazily, usually after every 60 seconds. This ensures that we have read-and-write access to databases that is almost as fast as memory.

Let's first study the format in which ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required