Module: Mongoid::Shardable

Extended by:
ActiveSupport::Concern
Included in:
Composable
Defined in:
lib/mongoid/shardable.rb

Overview

This module contains behaviour for adding shard key fields to updates.

Since:

  • 4.0.0

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#shard_key_fieldsArray<String>

Note:

Refactored from using delegate for class load performance.

Get the shard key fields.

Examples:

Get the shard key fields.

model.shard_key_fields

Returns:

  • (Array<String>)

    The shard key field names.

Since:

  • 1.0.0



25
26
27
# File 'lib/mongoid/shardable.rb', line 25

def shard_key_fields
  self.class.shard_key_fields
end

#shard_key_selectorHash

Get the document selector with the defined shard keys.

Examples:

Get the selector for the shard keys.

person.shard_key_selector

Returns:

  • (Hash)

    The shard key selector.

Since:

  • 2.0.0



37
38
39
40
41
42
43
# File 'lib/mongoid/shardable.rb', line 37

def shard_key_selector
  selector = {}
  shard_key_fields.each do |field|
    selector[field.to_s] = send(field)
  end
  selector
end