模块:Mongoid::Indexable::ClassMethods
- 定义于:
- lib/mongoid/indexable.rb
实例方法摘要折叠
-
#add_indexes ⇒ true
将默认索引添加到根文档(如果尚不存在)。
-
# create_indexes ⇒ true
将实际的索引创建注释发送到 MongoDB 驱动程序。
-
#index(spec, options = nil) ⇒ Hash
为提供的单键或复合键添加索引定义。
-
# index_specation (index_hash, index_name = nil) ⇒ 规范
获取所提供键的索引规范。
-
# remove_indexes ⇒ true
将实际的索引删除注释发送到MongoDB驱动程序,但保持_id不变。
实例方法详细信息
# add_indexes ⇒ true
将默认索引添加到根文档(如果尚不存在)。 目前这只是 _type。
72 73 74 75 76 77 |
# File 'lib/mongoid/indexable.rb', line 72 def add_indexes if 会遗传吗? && !index_keys.包括?(discriminator_key.to_sym => 1) 索引(index)({ discriminator_key.to_sym => 1 }, unique: false, 背景: true) end true end |
# create_indexes ⇒ true
将实际的索引创建注释发送到 MongoDB 驱动程序
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mongoid/indexable.rb', line 24 def create_indexes return 除非 index_specifications = { 背景: 配置.background_indexing } index_specifications.每 do |spec| key, = spec.key, .合并(merge)(spec.) if database = [:database] 通过(database: database) do |klass| klass.集合.索引(会话: _session).create_one(key, .除了(:database)) end else 集合.索引(会话: _session).create_one(key, ) end end 和 true end |
#index(spec, options = nil) ⇒ Hash
为提供的单键或复合键添加索引定义。
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mongoid/indexable.rb', line 92 def 索引(index)(spec, = nil) 规范 = 规范.new(self, spec, ) # Indexable::Specification 实例的相等性测试不会 # 考虑任何选项,这意味着不会比较名称。这意味着 # 一个索引具有与另一个索引不同的选项,并且不同 # 名称,除非有重复的索引声明,否则将被静默忽略 # 是允许的。 return 除非 Mongoid.allow_duplicate_index_declarations || !index_specifications.包括?(规范) index_specifications.推动(规范) end |
# index_specation (index_hash, index_name = nil) ⇒规范
获取所提供键的索引规范。
114 115 116 117 118 |
# File 'lib/mongoid/indexable.rb', line 114 def index_说明(index_hash, index_name = nil) index_specifications.检测 do |spec| spec.superficial_match?(键: index_hash, 名称: index_name) end end |
# remove_indexes ⇒ true
将实际的索引删除注释发送到MongoDB驱动程序,但保持_id不变。
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/mongoid/indexable.rb', line 48 def remove_indexes indexed_database_names.每 do |database| 通过(database: database) do |klass| klass.集合.索引(会话: _session).每 do |spec| 来年 if spec[' name '] == ' _id_ ' klass.集合.索引(会话: _session).drop_one(spec['key']) 记录器.信息( " MONGOID: Removed 索引 ' #{ spec [' name' ] } ' on 集合 " + " ' #{ klass . 集合 . name } ' in 数据库 ' #{ 数据库 } '. " ) end 救援 mongo::错误::OperationFailure end end 和 true end |