Module: Mongoid::Locking::Selectable

Defined in:
lib/mongoid/locking/selectable.rb

Overview

:nodoc:

Since:

  • 0.1.0

Instance Method Summary collapse

Instance Method Details

#atomic_selector(skip_lock_version: false) ⇒ Object

Overrides the default Mongoid::Selectable#atomic_selector to not memoize its result.

It is required when saving the same object multiple times in a row.

Since:

  • 0.1.0



8
9
10
# File 'lib/mongoid/locking/selectable.rb', line 8

def atomic_selector(skip_lock_version: false)
  embedded? ? embedded_atomic_selector : root_atomic_selector(skip_lock_version: skip_lock_version)
end

#root_atomic_selector(skip_lock_version: false) ⇒ Hash

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Get the atomic selector for a root document.

github.com/mongodb/mongoid/blob/7.2-stable/lib/mongoid/selectable.rb#L57

Examples:

Get the root atomic selector.

document.root_atomic_selector

Returns:

  • (Hash)

    The root document selector.

Since:

  • 4.0.0



23
24
25
26
27
# File 'lib/mongoid/locking/selectable.rb', line 23

def root_atomic_selector(skip_lock_version: false)
  return { "_id" => id, "lock_version" => lock_version }.merge!(shard_key_selector) unless skip_lock_version

  { "_id" => id }.merge!(shard_key_selector)
end