类:Mongoid::Contextual::MapReduce

继承:
对象
  • 对象
显示全部
扩展方式:
可转发
包括:
可枚举,命令
定义于:
lib/mongoid/contextual/map_reduce.rb

Overview

表示 mapReduce数据库命令指令。

实例属性摘要

命令包含的属性

# 集合 , # 集合要查询的集合。#criteria#criteria 上下文的条件。

实例方法摘要折叠

命令中包含的方法

#client

构造函数详情

#initialize (集合,riteria, map, reduce) ⇒ MapReduce

初始化新的 map/reduce 指令。

例子:

初始化新的 map/reduce。

MapReduce.new(criteria, map, reduce)

参数:

  • 条件 ( Criteria )

    Mongoid 标准。

  • map ( string )

    地图JavaScript函数。

  • 化简(reduce) ( string )

    reduce JavaScript函数。



77
78
79
80
81
# File 'lib/mongoid/contextual/map_reduce.rb', line 77

def 初始化(集合, 条件, map, 化简(reduce))
  @collection = 集合
  @criteria = 条件
  @map_reduce = @criteria.查看.map_reduce(map, 化简(reduce))
end

实例方法详细信息

#命令哈希

返回命令规范的选择器。

返回:

  • (哈希)

    选择器。



221
222
223
# File 'lib/mongoid/contextual/map_reduce.rb', line 221

def 命令
  @map_reduce.发送(:map_reduce_spec)[:selector]
end

# counts哈希

获取 map/reduce 返回的所有计数。

例子:

获取计数。

map_reduce.counts

返回:

  • (哈希)

    计数。



22
23
24
# File 'lib/mongoid/contextual/map_reduce.rb', line 22

def counts
  结果[" counts "]
end

#each枚举器

遍历 map/reduce 中的每个文档,不包括从数据库传回的额外信息。

例子:

对结果进行迭代。

map_reduce.each do |doc|
  p doc
end

返回:

  • (枚举器)

    枚举器。



35
36
37
38
39
40
41
42
43
44
# File 'lib/mongoid/contextual/map_reduce.rb', line 35

def 
  validate_out!
  if block_given?
    @map_reduce. do |doc|
      产量 doc
    end
  else
    @map_reduce.to_enum
  end
end

发出的数量 ⇒整数

获取 map/reduce 发出的文档数量。

例子:

获取发出的文档计数。

map_reduce.emitted

返回:

  • ( Integer )

    发出的文档数量。



52
53
54
# File 'lib/mongoid/contextual/map_reduce.rb', line 52

def 发出
  counts[" emit "]
end

# finalize (function) ⇒ MapReduce

为 map/reduce 提供 finalize JavaScript函数。

例子:

提供 finalize 函数。

map_reduce.finalize(func)

参数:

  • function ( string )

    finalize 函数。

返回:



64
65
66
67
# File 'lib/mongoid/contextual/map_reduce.rb', line 64

def finalize(function)
  @map_reduce = @map_reduce.finalize(function)
  self
end

#inputInteger

获取输入到 map/reduce 中的文档数。

例子:

获取输入文档的计数。

map_reduce.input

返回:

  • ( Integer )

    输入文档的数量。



89
90
91
# File 'lib/mongoid/contextual/map_reduce.rb', line 89

def 输入
  counts[" input "]
end

#检查string

获取 map/reduce 的美观string表示形式,包括条件、map、reduce、finalize 和 out 选项。

例子:

检查 map_reduce。

map_reduce.inspect

返回:

  • ( string )

    检查string 。



207
208
209
210
211
212
213
214
215
216
# File 'lib/mongoid/contextual/map_reduce.rb', line 207

def 检查
%Q{ #<Mongoid::Contextual::MapReduce 选择器: #{ riteria .选择器检查}类: #{条件. klass } map: #{ command [ :map ] } reduce: #{ command [ :reduce ] } finalize: #{ command [ :finalize ] } out: #{ command [ :out ] .检查} > }
end

#js_modeMapReduce

将 map/reduce 设置为使用 jsMode。

例子:

将 map/reduce 设置为 jsMode。

map_reduce.js_mode

返回:



99
100
101
102
# File 'lib/mongoid/contextual/map_reduce.rb', line 99

def js_mode
  @map_reduce = @map_reduce.js_mode(true)
  self
end

# out (位置) ⇒ MapReduce

指定 map/reduce 输出的存储位置。 请参阅 MongoDB 文档以了解支持的 map reduce 选项。

例子:

将输出存储在内存中。

map_reduce.out(inline: 1)

将输出存储在集合中,替换现有文档。

map_reduce.out(replace: "collection_name")

将输出存储在集合中,合并现有文档。

map_reduce.out(merge: "collection_name")

将输出存储在集合中,从而减少现有文档。

map_reduce.out(reduce: "collection_name")

返回 map reduce 的结果。

map_reduce.out(inline: 1)

参数:

  • 位置 (哈希)

    存储结果的位置。

返回:



125
126
127
128
129
130
131
132
# File 'lib/mongoid/contextual/map_reduce.rb', line 125

def out(位置)
  标准化 = 位置.dup
  标准化.transform_values! do ||
    .is_a?(::符号) ? .to_s : 
  end
  @map_reduce = @map_reduce.out(标准化)
  self
end

#outputInteger

获取 map/reduce 输出的文档数。

例子:

获取输出文档计数。

map_reduce.output

返回:

  • ( Integer )

    输出文档的数量。



140
141
142
# File 'lib/mongoid/contextual/map_reduce.rb', line 140

def 输出
  counts[" output "]
end

#原始哈希也称为:结果执行

获取 map/reduce 操作的原始输出。

例子:

获取原始输出。

map_reduce.raw

返回:

  • (哈希)

    原始输出。



150
151
152
153
154
155
# File 'lib/mongoid/contextual/map_reduce.rb', line 150

def 原始
  validate_out!
  cmd = 命令
  opts = { 读取: 条件.选项.获取(:read) } if 条件.选项[:read]
  @map_reduce.database.命令(cmd, (opts || {}).合并(merge)(会话: _session)).first
end

# Reduced整数

获取通过 map/reduce 减少的文档数。

例子:

获取减少的文档数。

map_reduce.reduced

返回:

  • ( Integer )

    减少的文档数量。



173
174
175
# File 'lib/mongoid/contextual/map_reduce.rb', line 173

def 减少
  counts[" reduce "]
end

#作用域(对象) ⇒ MapReduce

将 JavaScript对象添加到 map/reduce 的全局范围。

例子:

将对象添加到全局作用域。

map_reduce.scope(name: value)

参数:

  • 对象 (哈希)

    全局范围的键/值哈希。

返回:



185
186
187
188
# File 'lib/mongoid/contextual/map_reduce.rb', line 185

def 范围(对象)
  @map_reduce = @map_reduce.范围(对象)
  self
end

# timeFloat

获取 map/reduce 的执行时间。

例子:

获取执行时间。

map_reduce.time

返回:

  • (浮点)

    时间以毫秒为单位。



196
197
198
# File 'lib/mongoid/contextual/map_reduce.rb', line 196

def 时间
  结果[" timeMillis "]
end