module Mongoid::Shardable
This module contains behavior for adding shard key fields to updates.
@since 4.0.0
Public Instance Methods
shard_key_fields()
click to toggle source
Get the shard key fields.
@note Refactored from using delegate for class load performance.
@example Get the shard key fields.
model.shard_key_fields
@return [ Array<String> ] The shard key field names.
@since 1.0.0
# File lib/mongoid/shardable.rb, line 51 def shard_key_fields self.class.shard_key_fields end
shard_key_selector()
click to toggle source
Returns the selector that would match the current version of this document.
@return [ Hash ] The shard key selector.
@api private
# File lib/mongoid/shardable.rb, line 61 def shard_key_selector selector = {} shard_key_fields.each do |field| selector[field.to_s] = send(field) end selector end
shard_key_selector_in_db()
click to toggle source
Returns the selector that would match the existing version of this document in the database.
If the document is not persisted, this method uses the current values of the shard key fields. If the document is persisted, this method uses the values retrieved from the database.
@return [ Hash ] The shard key selector.
@api private
# File lib/mongoid/shardable.rb, line 79 def shard_key_selector_in_db selector = {} shard_key_fields.each do |field| selector[field.to_s] = new_record? ? send(field) : attribute_was(field) end selector end