类:Mongo::Collection::View::MapReduce
Overview
提供与集合视图上的 map/reduce 操作相关的行为。
常量摘要折叠
- INLINE =
内联选项。
'内联'- REROUTE =
已弃用。
重新路由消息。
'将 MapReduce 操作重新路由到主节点 (primary node in the replica set)服务器'
Loggable中包含的常量
实例属性摘要折叠
-
# map_function ⇒ string
只读
Map 映射函数。
-
# reduce_function ⇒ string
只读
化简 化简函数。
-
#view ⇒ View
只读
视图 集合视图。
包含在Immutable中的属性
实例方法摘要折叠
-
#每个{|Each| ... } ⇒ 枚举器
遍历 map/reduce 返回的文档。
-
#执行⇒ Mongo::Operation::Result
执行 map reduce,如果输出到集合,则无需执行提取查询来检索结果。
-
# finalize (function = nil) ⇒ MapReduce, string
设置或获取操作的 finalize 函数。
-
#initialize (view, map, reduce, options = {}) ⇒ MapReduce
构造函数
为提供的集合视图、函数和选项初始化 map/reduce。
-
# js_mode (value = nil) ⇒ MapReduce, ...
设置或获取操作的 jsMode 标志。
-
# out (location = nil) ⇒ MapReduce, Hash
设置或获取操作的输出位置。
-
#out_collection_name ⇒ Object
返回写入 map-reduce 结果的集合名称。
-
# out_database_name ⇒ 对象
返回写入 map-reduce 结果的数据库名称。
-
#scope (object = nil) ⇒ MapReduce, Hash
设置或获取操作的范围。
-
# verbose (value = nil) ⇒ MapReduce, Hash
是否在结果中包含计时信息。
Retryable 中包含的方法
#read_worker、#select_server、#with_overload_retry、#write_worker
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
构造函数详情
#initialize (view, map, reduce, options = {}) ⇒ MapReduce
为提供的集合视图、函数和选项初始化 map/reduce。
118 119 120 121 122 123 124 125 126 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 118 def 初始化(查看, map, 化简(reduce), = {}) @view = 查看 @map_function = map.dup.冻结 @reduce_function = 化简(reduce).dup.冻结 @options = BSON::文档.new().冻结 弃用.WARN(:map_reduce, ' map_reduce 操作已弃用,请改用聚合管道。 ') end |
实例属性详细信息
# map_function ⇒ string (readonly)
返回 map 映射函数。
46 47 48 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 46 def map_function @map_function end |
# reduce_function ⇒ string (readonly)
返回 reduce 该 reduce 函数。
49 50 51 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 49 def reduce_function @reduce_function end |
# view ⇒视图(只读)
返回视图集合视图。
43 44 45 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 43 def 查看 @view end |
实例方法详细信息
#每个{|Each| ... } ⇒枚举器
遍历 map/reduce 返回的文档。
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 69 def 每(和块) @cursor = nil 会话 = 客户端.get_session(@options) server = 集群.next_primary(nil, 会话) 上下文 = 操作::上下文.new(客户端: 客户端, 会话: 会话, operation_timeups: 查看.operation_timeups) if server.load_balancer? # 当游标耗尽时,将签入连接。 连接 = server.池.check_out(上下文: 上下文) 结果 = send_initial_query_with_connection(连接, 上下文.会话, 上下文: 上下文) 结果 = send_fetch_query_with_connection(连接, 会话) 除非 inline? else 结果 = send_initial_query(server, 上下文) 结果 = send_fetch_query(server, 会话) 除非 inline? end @cursor = Cursor.new(查看, 结果, server, 会话: 会话) if block_given? @cursor.每(和块) else @cursor.to_enum end end |
#执行⇒ Mongo::Operation::Result
执行 map reduce,如果输出到集合,则无需执行提取查询来检索结果。
229 230 231 232 233 234 235 236 237 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 229 def 执行 查看.发送(:with_session, @options) do |会话| write_concern = 查看.write_concern_with_session(会话) 上下文 = 操作::上下文.new(客户端: 客户端, 会话: 会话) nro_write_with_retry(write_concern, 上下文: 上下文) do |连接, _txn_num, 上下文| send_initial_query_with_connection(连接, 会话, 上下文: 上下文) end end end |
# finalize (function = nil) ⇒ MapReduce , string
设置或获取操作的 finalize 函数。
103 104 105 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 103 def finalize(function = nil) 配置(:finalize, function) end |
# js_mode (value = nil) ⇒ MapReduce , ...
设置或获取操作的 jsMode 标志。
139 140 141 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 139 def js_mode(值 = nil) 配置(:js_mode, 值) end |
# out (location = nil) ⇒ MapReduce , Hash
设置或获取操作的输出位置。
163 164 165 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 163 def out(位置 = nil) 配置(:out, 位置) end |
#out_collection_name ⇒ Object
返回写入 map-reduce 结果的集合名称。 如果结果以内联方式返回,则返回 nil。
169 170 171 172 173 174 175 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 169 def out_collection_name if [:out].respond_to?(:keys) [:out][OUT_ACTIONS.find do |操作| [:out][操作] end] end || [:out] end |
# out_database_name ⇒对象
返回写入 map-reduce 结果的数据库名称。 如果结果以内联方式返回,则返回 nil。
179 180 181 182 183 184 185 186 187 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 179 def out_database_name return 除非 [:out] if [:out].respond_to?(:keys) && (db = [:out][:db]) db else database.名称 end end |
#scope (object = nil) ⇒ MapReduce , Hash
设置或获取操作的范围。
200 201 202 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 200 def 范围(对象 = nil) 配置(:scope, 对象) end |
# verbose (value = nil) ⇒ MapReduce , Hash
是否在结果中包含计时信息。
216 217 218 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 216 def verbose(值 = nil) 配置(:verbose, 值) end |