类:Mongo::Collection::View::MapReduce

继承:
对象
  • 对象
显示全部
扩展方式:
可转发
包括:
可 枚举 不可变 、可记录、 可重试
定义于:
lib/ Mongo/ 集合/view/map_reduce.rb

Overview

提供与集合视图上的 map/reduce 操作相关的行为。

由于:

  • 2.0.0

常量摘要折叠

INLINE =

内联选项。

由于:

  • 2.1.0

'inline'.冻结
REROUTE =
已弃用。

重新路由消息。

由于:

  • 2.1.0

'将 MapReduce 操作重新路由到主节点 (primary node in the replica set)服务器。 '.冻结

Loggable中包含的常量

Loggable::PREFIX

实例属性摘要折叠

包含在Immutable中的属性

#options

实例方法摘要折叠

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。

例子:

创建新的 Map/Reduce 视图。

参数:

  • 查看 ( Collection::View )

    集合视图。

  • map ( string )

    地图函数。

  • 化简(reduce) ( string )

    reduce 函数。

  • 选项 哈希 (默认为: {}

    map/reduce 选项。

由于:

  • 2.0.0



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_functionstring (readonly)

返回 map 映射函数。

返回:

  • ( string )

    map 映射函数。

由于:

  • 2.0.0



48
49
50
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 48

def map_function
  @map_function
end

# reduce_functionstring (readonly)

返回 reduce 该 reduce 函数。

返回:

  • ( string )

    reducereduce 函数。

由于:

  • 2.0.0



51
52
53
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 51

def reduce_function
  @reduce_function
end

# view视图(只读)

返回视图集合视图。

返回:

  • ( View )

    view集合视图。

由于:

  • 2.0.0



45
46
47
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 45

def 查看
  @view
end

实例方法详细信息

#每个{|Each| ... } ⇒枚举器

遍历 map/reduce 返回的文档。

例子:

遍历 map/reduce 的结果。

map_reduce.each do |document|
  p document
end

收益参数:

  • 每个 (哈希)

    匹配文档。

返回:

  • (枚举器)

    枚举器。

由于:

  • 2.0.0



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.

例子:

执行 map reduce 并获取原始结果。

map_reduce.execute

返回:

由于:

  • 2.5.0



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 函数。

例子:

设置 finalize 函数。

map_reduce.finalize(function)

参数:

  • function string (默认为: nil

    finalize JavaScript函数。

返回:

  • ( MapReduce , string )

    新的 MapReduce 操作或函数值。

由于:

  • 2.0.0



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 标志。

例子:

为操作设置JavaScript模式。

map_reduce.js_mode(true)

参数:

  • ( true , false ) (默认为: nil

    jsMode 值。

返回:

  • ( MapReduce , true , false )

    新的 MapReduce 操作或 jsMode 标志的值。

由于:

  • 2.0.0



141
142
143
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 141

def js_mode( = nil)
  配置(:js_mode, )
end

# out (location = nil) ⇒ MapReduce , Hash

设置或获取操作的输出位置。

例子:

将输出设置为内联。

map_reduce.out(inline: 1)

将输出集合设置为合并。

map_reduce.out(merge: 'users')

设置要替换的输出集合。

map_reduce.out(replace: 'users')

将输出集合设置为 reduce。

map_reduce.out(reduce: 'users')

参数:

  • 位置 哈希 (默认为: nil

    输出位置详细信息。

返回:

  • ( MapReduce , Hash )

    新的 MapReduce 操作或输出位置的值。

由于:

  • 2.0.0



165
166
167
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 165

def out(位置 = nil)
  配置(:out, 位置)
end

#out_collection_nameObject

返回写入 map-reduce 结果的集合名称。 如果结果以内联方式返回,则返回 nil。

由于:

  • 2.0.0



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。

由于:

  • 2.0.0



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

设置或获取操作的范围。

例子:

设置范围值。

map_reduce.scope(value: 'test')

参数:

  • 对象 哈希 (默认为: nil

    范围对象。

返回:

  • ( MapReduce , Hash )

    新的 MapReduce 操作或作用域的值。

由于:

  • 2.0.0



202
203
204
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 202

def 范围(对象 = nil)
  配置(:scope, 对象)
end

# verbose (value = nil) ⇒ MapReduce , Hash

是否在结果中包含计时信息。

例子:

设置详细值。

map_reduce.verbose(false)

参数:

  • ( true , false ) (默认为: nil

    是否在结果中包含计时信息。

返回:

  • ( MapReduce , Hash )

    新的 MapReduce 操作或 verbose 选项的值。

由于:

  • 2.0.5



218
219
220
# File 'lib/ Mongo/ 集合/view/map_reduce.rb', line 218

def verbose( = nil)
  配置(:verbose, )
end