Module: Mongoid::Shardable::ClassMethods

Defined in:
build/mongoid-7.0/lib/mongoid/shardable.rb

Overview

Since:

  • 4.0.0

Instance Method Summary collapse

Instance Method Details

#shard_key(*names) ⇒ Object

Specifies a shard key with the field(s) specified.

Examples:

Specify the shard key.


class Person
  include Mongoid::Document
  field :first_name, :type => String
  field :last_name, :type => String

  shard_key :first_name, :last_name
end

Since:

  • 2.0.0



60
61
62
63
64
# File 'build/mongoid-7.0/lib/mongoid/shardable.rb', line 60

def shard_key(*names)
  names.each do |name|
    self.shard_key_fields << self.database_field_name(name).to_sym
  end
end