类:Mongo::Collection::View::MapReduce
Overview
提供与集合视图上的 map/reduce 操作相关的行为。
常量摘要折叠
- INLINE =
内联选项。
'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 、 #write_worker
Loggable中包含的方法
#log_debug 、 #log_error 、 #log_ Fatal 、 #log_info 、 #log_warn 、 #logger
构造函数详情
#initialize (view, map, reduce, options = {}) ⇒ MapReduce
为提供的集合视图、函数和选项初始化 map/reduce。
121 122 123 124 125 126 127 128 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 121 def 初始化(查看, map, 化简(reduce), = {}) @view = 查看 @map_function = map.dup.冻结 @reduce_function = 化简(reduce).dup.冻结 @options = BSON::文档.new().冻结 客户端.log_warn(' map_reduce 操作已弃用,请改用聚合管道') end |
实例属性详细信息
# map_function ⇒ string (readonly)
返回 map 映射函数。
48 49 50 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 48 def map_function @map_function end |
# reduce_function ⇒ string (readonly)
返回 reduce 该 reduce 函数。
51 52 53 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 51 def reduce_function @reduce_function end |
# view ⇒视图(只读)
返回视图集合视图。
45 46 47 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 45 def 查看 @view end |
实例方法详细信息
#每个{|Each| ... } ⇒枚举器
遍历 map/reduce 返回的文档。
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 71 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.每 do |doc| 产量 doc end else @cursor.to_enum end end |
#执行⇒ Mongo::Operation::Result
执行 map reduce,而不执行提取查询来检索结果
if outputted to a collection.
231 232 233 234 235 236 237 238 239 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 231 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 函数。
106 107 108 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 106 def finalize(function = nil) 配置(:finalize, function) end |
# js_mode (value = nil) ⇒ MapReduce , ...
设置或获取操作的 jsMode 标志。
141 142 143 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 141 def js_mode(值 = nil) 配置(:js_mode, 值) end |
# out (location = nil) ⇒ MapReduce , Hash
设置或获取操作的输出位置。
165 166 167 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 165 def out(位置 = nil) 配置(:out, 位置) end |
#out_collection_name ⇒ Object
返回写入 map-reduce 结果的集合名称。 如果结果以内联方式返回,则返回 nil。
171 172 173 174 175 176 177 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 171 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。
181 182 183 184 185 186 187 188 189 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 181 def out_database_name if [:out] if [:out].respond_to?(:keys) && (db = [:out][:db]) db else database.名称 end end end |
#scope (object = nil) ⇒ MapReduce , Hash
设置或获取操作的范围。
202 203 204 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 202 def 范围(对象 = nil) 配置(:scope, 对象) end |
# verbose (value = nil) ⇒ MapReduce , Hash
是否在结果中包含计时信息。
218 219 220 |
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 218 def verbose(值 = nil) 配置(:verbose, 值) end |