类:Mongoid::Contextual::Memory
- 继承:
-
对象
- 对象
- Mongoid::Contextual::Memory
- 包括:
- Enumerable、 Association::EagerLoadable 、 Aggregable::Memory 、 Queryable 、 Positional
- 定义于:
- lib/mongoid/contextual/memory.rb
Overview
用于对已加载到应用程序内存中的文档执行批量查询和持久化操作的 Context对象。 该类的方法接口与 Mongoid::Contextual::Mongo一致。
实例属性摘要折叠
-
# 个文档⇒ 对象
只读
返回属性文档的值。
- #匹配与选择器匹配的内存文档。 (The) ⇒ 对象 只读
-
#路径⇒ 对象
只读
返回属性路径的值。
- # path 原子路径。 (Theatomicpath。) ⇒ 对象 只读
-
# root ⇒ 对象
只读
返回属性根的值。
- # root 根文档。 (根文档。) ⇒ 对象 只读
-
#选择器⇒ 对象
只读
返回属性选择器的值。
- #选择器 根文档选择器。 (根文档选择器。)⇒ 对象 只读
Queryable中包含的属性
#collection 、 #collection 要查询的集合。 、 #criteria 、 #criteria 上下文的条件。 、 #klass 、 #klass 条件的 klass。
实例方法摘要折叠
-
# == (other) ⇒ true | false
检查上下文是否等于其他对象。
-
# 删除 ⇒ nil (又名:#delete_all)
删除数据库中与选择器匹配的所有文档。
-
#destroy ⇒ nil (也:#destroy_all)
销毁数据库中与选择器匹配的所有文档。
-
# distinct (field) ⇒ Array<Object>
获取数据库中所提供字段的非重复值。
-
#each ⇒ 枚举器
遍历上下文。
-
#是否存在? (id_or_conditions = :none) ⇒ true | false
该上下文是否存在任何文档。
-
#第五个⇒ 文档
获取数据库中条件选择器的第五个文档。
-
#第五! ⇒ 文档
获取数据库中条件选择器的第五个文档,如果未找到,则引发错误。
-
# first (limit = nil) ⇒ 文档(也:#one、#find_first)
获取数据库中符合条件的选择器的第一个文档。
-
# first! ⇒ 文档
获取数据库中条件选择器的第一个文档,如果未找到任何文档,则引发错误。
-
#fourth ⇒ 文档
获取数据库中条件选择器的第四个文档。
-
#fourth! ⇒ 文档
获取数据库中条件选择器的第四个文档,如果未找到,则引发错误。
-
#inc(incs) ⇒ Enumerator
递增所有文档的值。
-
#initialize (criteria) ⇒ 内存
构造函数
在内存上下文中创建新内容。
-
#last(limit = nil) ⇒ Document
获取数据库中符合条件的选择器的最后一个文档。
-
#last! ⇒ Document
获取数据库中条件选择器的最后一个文档,如果未找到任何文档,则引发错误。
-
# length ⇒ Integer (也称为:#size)
获取上下文中匹配文档的长度。
-
# limit (value) ⇒ 内存
限制返回的文档数量。
-
# pick (*fields) ⇒ 对象 | Array<Object>
选择内存中的字段值。
-
# pluck (*fields) ⇒ Array<Object> | Array<Array<Object>>
提取内存中的字段值。
-
#秒⇒ 文档
获取数据库中条件选择器的第二个文档。
-
#秒! ⇒ 文档
获取数据库中条件选择器的第二个文档,如果未找到,则引发错误。
-
# Second_to_last ⇒ 文档
获取数据库中条件选择器的倒数第二个文档。
-
# Second_to_last! ⇒ 文档
获取数据库中条件选择器的倒数第二个文档,如果未找到任何文档,则引发错误。
-
# skip (value) ⇒ 内存
跳过所提供数量的文档。
-
#sort(values) ⇒ Memory
按提供的规范对文档进行排序。
-
#take(limit = nil) ⇒ Document
从数据库中获取给定数量的文档。
-
#take! ⇒ Document
从数据库中获取给定数量的文档,如果未找到任何文档,则引发错误。
-
#tally (字段)→ 哈希
统计内存中的字段值。
-
# Third ⇒ 文档
在数据库中获取条件选择器的第三个文档。
-
# Third! ⇒ 文档
在数据库中获取条件选择器的第三个文档,如果未找到,则引发错误。
-
# Third_to_last ⇒ 文档
获取数据库中倒数第三个文档作为条件的选择器。
-
# Third_to_last! ⇒ 文档
获取数据库中倒数第三个文档作为条件选择器,如果未找到,则引发错误。
-
# update (attributes = nil) ⇒ nil | false
自动更新第一个匹配的文档。
-
#update_all(attributes = nil) ⇒ nil | false
自动更新所有匹配的文档。
位置包含的方法
Queryable中包含的方法
Association::EagerLoadable 中包含的方法
#eager_load 、 #eager_loadable? , #preload
Aggregable::Memory中包含的方法
#aggregates 、 #avg 、 #max 、 #min 、 #sum
构造函数详情
实例属性详细信息
# 个documents ⇒对象(只读)
返回属性文档的值。
25 26 27 |
# File 'lib/mongoid/contextual/memory.rb', line 25 def 文档 @documents end |
#匹配与选择器匹配的内存文档。 (The) ⇒对象(只读)
25 |
# File 'lib/mongoid/contextual/memory.rb', line 25 attr_reader :documents, :path, :root, :selector |
#路径⇒对象(只读)
返回属性路径的值。
25 26 27 |
# File 'lib/mongoid/contextual/memory.rb', line 25 def 路径 @path end |
# path 原子路径。 (Theatomicpath。) ⇒对象(只读)
25 |
# File 'lib/mongoid/contextual/memory.rb', line 25 attr_reader :documents, :path, :root, :selector |
# root 根文档。 (根文档。) ⇒对象(只读)
25 |
# File 'lib/mongoid/contextual/memory.rb', line 25 attr_reader :documents, :path, :root, :selector |
#选择器⇒对象(只读)
返回属性选择器的值。
25 26 27 |
# File 'lib/mongoid/contextual/memory.rb', line 25 def 选择器 @selector end |
#选择器 根文档选择器。 (根文档选择器。)⇒对象(只读)
25 |
# File 'lib/mongoid/contextual/memory.rb', line 25 attr_reader :documents, :path, :root, :selector |
实例方法详细信息
# == (other) ⇒ true | false
检查上下文是否等于其他对象。
35 36 37 38 |
# File 'lib/mongoid/contextual/memory.rb', line 35 def ==(其他) return false 除非 其他.respond_to?(:entries) 条目 == 其他.条目 end |
# delete ⇒ nil也称为: delete_all
删除数据库中与选择器匹配的所有文档。
46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mongoid/contextual/memory.rb', line 46 def 删除 Deleted = 数数 已删除 = map do |doc| prepare_remove(doc) doc.发送(:as_attributes) end 除非 已删除.空? 集合.find(选择器).update_one( 按位置(选择器, " $pullAll " => { 路径 => 已删除 }), 会话: _session ) end Deleted end |
#destroy ⇒ nil也称为: destroy_all
销毁数据库中与选择器匹配的所有文档。
68 69 70 71 72 73 74 75 |
# File 'lib/mongoid/contextual/memory.rb', line 68 def 销毁 Deleted = 数数 每 do |doc| 文档.delete_one(doc) doc.销毁 end Deleted end |
# distinct (field) ⇒ Array<Object>
获取数据库中所提供字段的非重复值。
86 87 88 |
# File 'lib/mongoid/contextual/memory.rb', line 86 def distinct(字段) 采摘(字段).uniq end |
#each ⇒枚举器
遍历上下文。 如果提供了区块,则为每个区块让出一个 Mongoid文档,否则返回一个枚举。
99 100 101 102 103 104 105 106 107 108 |
# File 'lib/mongoid/contextual/memory.rb', line 99 def 每 if block_given? documents_for_iteration.每 do |doc| 产量(doc) end self else to_enum end end |
#是否存在? (id_or_conditions = :none) ⇒ true | false
该上下文是否存在任何文档。
126 127 128 129 130 131 132 133 |
# File 'lib/mongoid/contextual/memory.rb', line 126 def 存在吗?(id_or_conditions = : none) 案例 id_or_conditions when : none then 任何? when nil, false then false when 哈希 then 内存.new(条件.WHERE(id_or_conditions)).存在吗? else 内存.new(条件.WHERE(_id: id_or_conditions)).存在吗? end end |
#第五个⇒文档
获取数据库中条件选择器的第五个文档。
454 455 456 |
# File 'lib/mongoid/contextual/memory.rb', line 454 def 第五 ager_load([文档.第五]).first end |
#第五! ⇒文档
获取数据库中条件选择器的第五个文档,如果未找到,则引发错误。
468 469 470 |
# File 'lib/mongoid/contextual/memory.rb', line 468 def 第五! 第五 || Raise_document_not_Found_error end |
# first (limit = nil) ⇒文档也称为: one 、 find_first
获取数据库中符合条件的选择器的第一个文档。
143 144 145 146 147 148 149 |
# File 'lib/mongoid/contextual/memory.rb', line 143 def first(limit = nil) if limit ager_load(文档.first(limit)) else ager_load([文档.first]).first end end |
# first! ⇒文档
获取数据库中条件选择器的第一个文档,如果未找到任何文档,则引发错误。
163 164 165 |
# File 'lib/mongoid/contextual/memory.rb', line 163 def 首先! first || Raise_document_not_Found_error end |
#fourth ⇒文档
获取数据库中条件选择器的第四个文档。
430 431 432 |
# File 'lib/mongoid/contextual/memory.rb', line 430 def 第四 ager_load([文档.第四]).first end |
#fourth! ⇒文档
获取数据库中条件选择器的第四个文档,如果未找到,则引发错误。
444 445 446 |
# File 'lib/mongoid/contextual/memory.rb', line 444 def 第四! 第四 || Raise_document_not_Found_error end |
# inc (incs) ⇒枚举器
递增所有文档的值。
192 193 194 195 196 |
# File 'lib/mongoid/contextual/memory.rb', line 192 def inc(incs) 每 do |文档| 文档.inc(incs) end end |
#last(limit = nil) ⇒ Document
获取数据库中符合条件的选择器的最后一个文档。
206 207 208 209 210 211 212 |
# File 'lib/mongoid/contextual/memory.rb', line 206 def last(limit = nil) if limit ager_load(文档.last(limit)) else ager_load([文档.last]).first end end |
# last! ⇒文档
获取数据库中条件选择器的最后一个文档,如果未找到任何文档,则引发错误。
224 225 226 |
# File 'lib/mongoid/contextual/memory.rb', line 224 def last! last || Raise_document_not_Found_error end |
# length ⇒ Integer也称为:大小
获取上下文中匹配文档的长度。
234 235 236 |
# File 'lib/mongoid/contextual/memory.rb', line 234 def 长度 文档.长度 end |
# limit (value) ⇒内存
限制返回的文档数量。
247 248 249 250 |
# File 'lib/mongoid/contextual/memory.rb', line 247 def limit(值) self.限制 = 值 self end |
# pick (*fields) ⇒对象 | Array<Object>
选择内存中的字段值。
274 275 276 277 278 |
# File 'lib/mongoid/contextual/memory.rb', line 274 def pick(*字段) if doc = 文档.first puck_from_doc(doc, *字段) end end |
# pluck (*fields) ⇒ Array<Object> | Array<Array<Object>>
提取内存中的字段值。
260 261 262 263 264 |
# File 'lib/mongoid/contextual/memory.rb', line 260 def 采摘(*字段) 文档.map do |doc| puck_from_doc(doc, *字段) end end |
#秒⇒文档
获取数据库中条件选择器的第二个文档。
382 383 384 |
# File 'lib/mongoid/contextual/memory.rb', line 382 def 秒 ager_load([文档.秒]).first end |
#秒! ⇒文档
获取数据库中条件选择器的第二个文档,如果未找到,则引发错误。
396 397 398 |
# File 'lib/mongoid/contextual/memory.rb', line 396 def 第二! 秒 || Raise_document_not_Found_error end |
# Second_to_last ⇒文档
获取数据库中条件选择器的倒数第二个文档。
478 479 480 |
# File 'lib/mongoid/contextual/memory.rb', line 478 def Second_to_last ager_load([文档.Second_to_last]).first end |
# Second_to_last! ⇒文档
获取数据库中条件选择器的倒数第二个文档,如果未找到任何文档,则引发错误。
492 493 494 |
# File 'lib/mongoid/contextual/memory.rb', line 492 def Second_to_last! Second_to_last || Raise_document_not_Found_error end |
# skip (value) ⇒内存
跳过所提供数量的文档。
334 335 336 337 |
# File 'lib/mongoid/contextual/memory.rb', line 334 def 跳过(值) self.skipping = 值 self end |
#sort(values) ⇒ Memory
按提供的规范对文档进行排序。
348 349 350 |
# File 'lib/mongoid/contextual/memory.rb', line 348 def sort(values) in_place_sort(values) 和 self end |
#take(limit = nil) ⇒ Document
从数据库中获取给定数量的文档。
304 305 306 307 308 309 310 |
# File 'lib/mongoid/contextual/memory.rb', line 304 def 采取(limit = nil) if limit ager_load(文档.采取(limit)) else ager_load([文档.first]).first end end |
#take! ⇒ Document
从数据库中获取给定数量的文档,如果未找到任何文档,则引发错误。
322 323 324 |
# File 'lib/mongoid/contextual/memory.rb', line 322 def 采取! 采取 || Raise_document_not_Found_error end |
#tally (字段)→哈希
统计内存中的字段值。
288 289 290 291 292 293 294 |
# File 'lib/mongoid/contextual/memory.rb', line 288 def 计数(字段) return 文档.each_with_object({}) do |d, acc| v = retrieve_value_at_path(d, 字段) acc[v] ||= 0 acc[v] += 1 end end |
# Third ⇒文档
在数据库中获取条件选择器的第三个文档。
406 407 408 |
# File 'lib/mongoid/contextual/memory.rb', line 406 def 第三 ager_load([文档.第三]).first end |
# Third! ⇒文档
在数据库中获取条件选择器的第三个文档,如果未找到,则引发错误。
420 421 422 |
# File 'lib/mongoid/contextual/memory.rb', line 420 def 第三! 第三 || Raise_document_not_Found_error end |
# Third_to_last ⇒文档
获取数据库中倒数第三个文档作为条件的选择器。
502 503 504 |
# File 'lib/mongoid/contextual/memory.rb', line 502 def Third_to_last ager_load([文档.Third_to_last]).first end |
# Third_to_last! ⇒文档
获取数据库中倒数第三个文档作为条件选择器,如果未找到,则引发错误。
516 517 518 |
# File 'lib/mongoid/contextual/memory.rb', line 516 def Third_to_last! Third_to_last || Raise_document_not_Found_error end |
# update (attributes = nil) ⇒ nil | false
自动更新第一个匹配的文档。
360 361 362 |
# File 'lib/mongoid/contextual/memory.rb', line 360 def update(属性 = nil) update_documents(属性, [ first ]) end |
# update_all (attributes = nil) ⇒ nil | false
自动更新所有匹配的文档。
372 373 374 |
# File 'lib/mongoid/contextual/memory.rb', line 372 def update_all(属性 = nil) update_documents(属性, 条目) end |