类: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 (&block) ⇒ 枚举器
遍历上下文。
-
#是否存在? (id_or_conditions = :none) ⇒ true | false
该上下文是否存在任何文档。
-
#第五个⇒ 文档
获取数据库中条件选择器的第五个 document。
-
#第五! ⇒ 文档
获取数据库中条件选择器的第五个document,如果未找到,则引发错误。
-
# first (limit = nil) ⇒ 文档(也:#one、#find_first)
Get数据库中符合条件的选择器的第一个document。
-
# first! ⇒ 文档
获取数据库中条件选择器的第一个 document,如果未找到任何 document,则引发错误。
-
#fourth ⇒ 文档
获取数据库中条件选择器的第四个 document。
-
#fourth! ⇒ 文档
获取数据库中条件选择器的第四个document,如果未找到,则引发错误。
-
#inc(incs) ⇒ Enumerator
递增所有文档的值。
-
#initialize (criteria) ⇒ 内存
构造函数
在内存上下文中创建新内容。
-
#last(limit = nil) ⇒ Document
获取数据库中符合条件的选择器的最后一个文档。
-
#last! ⇒ Document
获取数据库中条件选择器的最后一个 document,如果未找到任何 document,则引发错误。
-
# length ⇒ Integer (也称为:#size)
获取上下文中匹配文档的长度。
-
# limit (value) ⇒ 内存
限制返回的文档数量。
-
# pick (*fields) ⇒ 对象 | Array<Object>
选择内存中的字段值。
-
# pluck (*fields) ⇒ Array<Object> | Array<Array<Object>>
提取内存中的字段值。
-
#秒⇒ 文档
获取数据库中条件选择器的第二个document。
-
#秒! ⇒ 文档
获取数据库中条件选择器的第二个document,如果未找到,则引发错误。
-
# Second_to_last ⇒ 文档
获取数据库中条件选择器的倒数第二个 document。
-
# Second_to_last! ⇒ 文档
获取数据库中条件选择器的倒数第二个 document,如果未找到任何 document,则引发错误。
-
# skip (value) ⇒ 内存
跳过所提供数量的文档。
-
#sort(values) ⇒ Memory
按提供的规范对文档进行排序。
-
#take(limit = nil) ⇒ Document
从数据库中获取给定数量的文档。
-
#take! ⇒ Document
从数据库中获取给定数量的文档,如果未找到任何文档,则引发错误。
-
#tally (字段)→ 哈希
统计内存中的字段值。
-
# Third ⇒ 文档
在数据库中获取条件选择器的第三个文档。
-
# Third! ⇒ 文档
在数据库中获取条件选择器的第三个document,如果未找到,则引发错误。
-
# Third_to_last ⇒ 文档
获取数据库中倒数第三个document作为条件的选择器。
-
# Third_to_last! ⇒ 文档
获取数据库中倒数第三个document作为条件选择器,如果未找到,则引发错误。
-
# update (attributes = nil) ⇒ nil | false
自动更新第一个匹配的文档。
-
#update_all(attributes = nil) ⇒ nil | false
自动更新所有匹配的文档。
位置包含的方法
Queryable中包含的方法
Association::EagerLoadable 中包含的方法
#create_pipeline、#eager_load、#eager_load_with_lookup、#eager_loadable?、#preload、#preload_for_lookup、#switch_local_and_foreign_fields?
Aggregable::Memory中包含的方法
#aggregates 、 #avg 、 #max 、 #min 、 #sum
构造函数详情
实例属性详细信息
# 个documents ⇒对象(只读)
返回属性文档的值。
23 24 25 |
# File 'lib/mongoid/contextual/memory.rb', line 23 def 文档 @documents end |
#匹配与选择器匹配的内存文档。 (The) ⇒对象(只读)
23 |
# File 'lib/mongoid/contextual/memory.rb', line 23 attr_reader :documents, :path, :root, :selector |
#路径⇒对象(只读)
返回属性路径的值。
23 24 25 |
# File 'lib/mongoid/contextual/memory.rb', line 23 def 路径 @path end |
# path 原子路径。 (Theatomicpath。) ⇒对象(只读)
23 |
# File 'lib/mongoid/contextual/memory.rb', line 23 attr_reader :documents, :path, :root, :selector |
# root 根文档。 (根文档。) ⇒对象(只读)
23 |
# File 'lib/mongoid/contextual/memory.rb', line 23 attr_reader :documents, :path, :root, :selector |
#选择器⇒对象(只读)
返回属性选择器的值。
23 24 25 |
# File 'lib/mongoid/contextual/memory.rb', line 23 def 选择器 @selector end |
#选择器 根文档选择器。 (根文档选择器。)⇒对象(只读)
23 |
# File 'lib/mongoid/contextual/memory.rb', line 23 attr_reader :documents, :path, :root, :selector |
实例方法详细信息
# == (other) ⇒ true | false
检查上下文是否等于其他对象。
33 34 35 36 37 |
# File 'lib/mongoid/contextual/memory.rb', line 33 def ==(其他) return false 除非 其他.respond_to?(:entries) 条目 == 其他.条目 end |
# delete ⇒ nil也称为: delete_all
删除数据库中与选择器匹配的所有文档。
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/mongoid/contextual/memory.rb', line 45 def 删除 Deleted = 数数 已删除 = map do |doc| prepare_remove(doc) doc.发送(:as_attributes) end 除非 已删除.空? 集合.find(选择器).update_one( 按位置(选择器, '$pullAll' => { 路径 => 已删除 }), 会话: _session ) end Deleted end |
#destroy ⇒ nil也称为: destroy_all
销毁数据库中与选择器匹配的所有文档。
67 68 69 70 71 72 73 74 |
# File 'lib/mongoid/contextual/memory.rb', line 67 def 销毁 Deleted = 数数 每 do |doc| 文档.delete_one(doc) doc.销毁 end Deleted end |
# distinct (field) ⇒ Array<Object>
获取数据库中所提供字段的非重复值。
85 86 87 |
# File 'lib/mongoid/contextual/memory.rb', line 85 def distinct(字段) 采摘(字段).uniq end |
#each (&block) ⇒枚举器
遍历上下文。 如果提供了区块,则为每个区块让出一个 Mongoid文档,否则返回一个枚举。
98 99 100 101 102 103 104 105 |
# File 'lib/mongoid/contextual/memory.rb', line 98 def 每(和块) if block_given? documents_for_iteration.每(和块) self else to_enum end end |
#是否存在? (id_or_conditions = :none) ⇒ true | false
该上下文是否存在任何文档。
123 124 125 126 127 128 129 130 |
# File 'lib/mongoid/contextual/memory.rb', line 123 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 |
#第五个⇒文档
获取数据库中条件选择器的第五个 document。
456 457 458 |
# File 'lib/mongoid/contextual/memory.rb', line 456 def 第五 ager_load([ 文档.第五 ]).first end |
#第五! ⇒文档
获取数据库中条件选择器的第五个document,如果未找到,则引发错误。
470 471 472 |
# File 'lib/mongoid/contextual/memory.rb', line 470 def 第五! 第五 || Raise_document_not_Found_error end |
# first (limit = nil) ⇒文档也称为: one 、 find_first
Get数据库中符合条件的选择器的第一个document。
140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mongoid/contextual/memory.rb', line 140 def first(limit = nil) use_first = limit.nil? limit ||= 1 if 条件.use_lookup? @criteria = 条件.limit(limit) 结果 = Eager_load_with_lookup else 结果 = ager_load(文档.first(limit)) end use_first ? 结果.first : 结果 end |
# first! ⇒文档
获取数据库中条件选择器的第一个 document,如果未找到任何 document,则引发错误。
165 166 167 |
# File 'lib/mongoid/contextual/memory.rb', line 165 def 首先! first || Raise_document_not_Found_error end |
#fourth ⇒文档
获取数据库中条件选择器的第四个 document。
432 433 434 |
# File 'lib/mongoid/contextual/memory.rb', line 432 def 第四 ager_load([ 文档.第四 ]).first end |
#fourth! ⇒文档
获取数据库中条件选择器的第四个document,如果未找到,则引发错误。
446 447 448 |
# File 'lib/mongoid/contextual/memory.rb', line 446 def 第四! 第四 || Raise_document_not_Found_error end |
# inc (incs) ⇒枚举器
递增所有文档的值。
194 195 196 197 198 |
# File 'lib/mongoid/contextual/memory.rb', line 194 def inc(incs) 每 do |文档| 文档.inc(incs) end end |
#last(limit = nil) ⇒ Document
获取数据库中符合条件的选择器的最后一个文档。
208 209 210 211 212 213 214 |
# File 'lib/mongoid/contextual/memory.rb', line 208 def last(limit = nil) if limit ager_load(文档.last(limit)) else ager_load([ 文档.last ]).first end end |
# last! ⇒文档
获取数据库中条件选择器的最后一个 document,如果未找到任何 document,则引发错误。
226 227 228 |
# File 'lib/mongoid/contextual/memory.rb', line 226 def last! last || Raise_document_not_Found_error end |
# length ⇒ Integer也称为:大小
获取上下文中匹配文档的长度。
236 237 238 |
# File 'lib/mongoid/contextual/memory.rb', line 236 def 长度 文档.长度 end |
# limit (value) ⇒内存
限制返回的文档数量。
249 250 251 252 |
# File 'lib/mongoid/contextual/memory.rb', line 249 def limit(值) self.限制 = 值 self end |
# pick (*fields) ⇒对象 | Array<Object>
选择内存中的字段值。
276 277 278 279 280 |
# File 'lib/mongoid/contextual/memory.rb', line 276 def pick(*字段) return 除非 doc = 文档.first puck_from_doc(doc, *字段) end |
# pluck (*fields) ⇒ Array<Object> | Array<Array<Object>>
提取内存中的字段值。
262 263 264 265 266 |
# File 'lib/mongoid/contextual/memory.rb', line 262 def 采摘(*字段) 文档.map do |doc| puck_from_doc(doc, *字段) end end |
#秒⇒文档
获取数据库中条件选择器的第二个document。
384 385 386 |
# File 'lib/mongoid/contextual/memory.rb', line 384 def 秒 ager_load([ 文档.秒 ]).first end |
#秒! ⇒文档
获取数据库中条件选择器的第二个document,如果未找到,则引发错误。
398 399 400 |
# File 'lib/mongoid/contextual/memory.rb', line 398 def 第二! 秒 || Raise_document_not_Found_error end |
# Second_to_last ⇒文档
获取数据库中条件选择器的倒数第二个 document。
480 481 482 |
# File 'lib/mongoid/contextual/memory.rb', line 480 def Second_to_last ager_load([ 文档.Second_to_last ]).first end |
# Second_to_last! ⇒文档
获取数据库中条件选择器的倒数第二个 document,如果未找到任何 document,则引发错误。
494 495 496 |
# File 'lib/mongoid/contextual/memory.rb', line 494 def Second_to_last! Second_to_last || Raise_document_not_Found_error end |
# skip (value) ⇒内存
跳过所提供数量的文档。
336 337 338 339 |
# File 'lib/mongoid/contextual/memory.rb', line 336 def 跳过(值) self.skipping = 值 self end |
#sort(values) ⇒ Memory
按提供的规范对文档进行排序。
350 351 352 |
# File 'lib/mongoid/contextual/memory.rb', line 350 def sort(values) in_place_sort(values) 和 self end |
#take(limit = nil) ⇒ Document
从数据库中获取给定数量的文档。
306 307 308 309 310 311 312 |
# File 'lib/mongoid/contextual/memory.rb', line 306 def 采取(limit = nil) if limit ager_load(文档.采取(limit)) else ager_load([ 文档.first ]).first end end |
#take! ⇒ Document
从数据库中获取给定数量的文档,如果未找到任何文档,则引发错误。
324 325 326 |
# File 'lib/mongoid/contextual/memory.rb', line 324 def 采取! 采取 || Raise_document_not_Found_error end |
#tally (字段)→哈希
统计内存中的字段值。
290 291 292 293 294 295 296 |
# File 'lib/mongoid/contextual/memory.rb', line 290 def 计数(字段) 文档.each_with_object({}) do |d, acc| v = retrieve_value_at_path(d, 字段) acc[v] ||= 0 acc[v] += 1 end end |
# Third ⇒文档
在数据库中获取条件选择器的第三个文档。
408 409 410 |
# File 'lib/mongoid/contextual/memory.rb', line 408 def 第三 ager_load([ 文档.第三 ]).first end |
# Third! ⇒文档
在数据库中获取条件选择器的第三个document,如果未找到,则引发错误。
422 423 424 |
# File 'lib/mongoid/contextual/memory.rb', line 422 def 第三! 第三 || Raise_document_not_Found_error end |
# Third_to_last ⇒文档
获取数据库中倒数第三个document作为条件的选择器。
504 505 506 |
# File 'lib/mongoid/contextual/memory.rb', line 504 def Third_to_last ager_load([ 文档.Third_to_last ]).first end |
# Third_to_last! ⇒文档
获取数据库中倒数第三个document作为条件选择器,如果未找到,则引发错误。
518 519 520 |
# File 'lib/mongoid/contextual/memory.rb', line 518 def Third_to_last! Third_to_last || Raise_document_not_Found_error end |
# update (attributes = nil) ⇒ nil | false
自动更新第一个匹配的文档。
362 363 364 |
# File 'lib/mongoid/contextual/memory.rb', line 362 def update(属性 = nil) update_documents(属性, [ first ]) end |
# update_all (attributes = nil) ⇒ nil | false
自动更新所有匹配的文档。
374 375 376 |
# File 'lib/mongoid/contextual/memory.rb', line 374 def update_all(属性 = nil) update_documents(属性, 条目) end |