模块: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。
76 77 78 79 80 81 |
# File 'lib/mongoid/indexable.rb', line 76 def add_indexes if 会遗传吗? && !index_keys.包括?(self.discriminator_key.to_sym => 1) 索引(index)({ self.discriminator_key.to_sym => 1 }, unique: false, 背景: true) end true end |
# create_indexes ⇒ true
将实际的索引创建注释发送到 MongoDB 驱动程序
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mongoid/indexable.rb', line 27 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
为提供的单键或复合键添加索引定义。
96 97 98 99 100 101 |
# File 'lib/mongoid/indexable.rb', line 96 def 索引(index)(spec, = nil) 规范 = 规范.new(self, spec, ) if !index_specifications.包括?(规范) index_specifications.推动(规范) end end |
# index_specation (index_hash, index_name = nil) ⇒规范
获取所提供键的索引规范。
112 113 114 115 116 117 |
# File 'lib/mongoid/indexable.rb', line 112 def index_说明(index_hash, index_name = nil) 索引(index) = OpenStruct.new(字段: index_hash.密钥, 键: index_hash) index_specifications.检测 do |spec| spec == 索引(index) || (index_name && index_name == spec.名称) end end |
# remove_indexes ⇒ true
将实际的索引删除注释发送到MongoDB驾驶员,但保持_id不变。
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/mongoid/indexable.rb', line 51 def remove_indexes indexed_database_names.每 do |database| 通过(database: database) do |klass| 开始 klass.集合.索引(会话: _session).每 do |spec| 除非 spec[" name "] == " _id_ " klass.集合.索引(会话: _session).drop_one(spec[" key "]) 记录器.信息( " MONGOID: Removed 索引 ' #{ spec [ " name " ] } ' on 集合 " + " ' #{ klass . 集合 . name } ' in 数据库 ' #{ 数据库 } '. " ) end end 救援 mongo::错误::OperationFailure; end end end 和 true end |