Module Mongoid::Safety
In: lib/mongoid/safety.rb

The Safety module is used to provide a DSL to execute database operations in safe mode on a per query basis, either from the Document class level or instance level.

Methods

Public Class methods

Static class method of easily getting the desired safe mode options from anywhere in the framework.

@example Get the options with safe mode included.

  Safety.merge_safety_options({ :safe => false })

@param [ Hash ] options The persistence options.

@return [ Hash ] The options hash.

@since 2.1.0

Public Instance methods

Execute the following instance-level persistence operation in safe mode.

@example Upsert in safe mode.

  person.safely.upsert

@example Destroy in safe mode with w and fsync options.

  person.safely(:w => 2, :fsync => true).destroy

@param [ Hash ] options The safe mode options.

@option options [ Integer ] :w The number of nodes to write to. @option options [ Integer ] :wtimeout Time to wait for return from all

  nodes.

@option options [ true, false ] :fsync Should a fsync occur.

@return [ Proxy ] The safety proxy.

Execute the following instance-level persistence operation without safe mode. Allows per-request overriding of safe mode when the persist_in_safe_mode config option is turned on.

@example Upsert in safe mode.

  person.unsafely.upsert

@return [ Proxy ] The safety proxy.

[Validate]