模块:Mongoid::Criteria::Queryable::Aggregable

扩展方式:
可宏
包含在:
Mongoid::Criteria::Queryable
定义于:
lib/mongoid/criteria/queryable/aggregable.rb

Overview

围绕创建聚合框架命令提供 DSL。

实例属性摘要折叠

实例方法摘要折叠

Macroable包含的方法

key

实例属性详细信息

# aggregating 指示我们是否正在聚合的标志。 (标志) ⇒对象


16
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16

attr_writer :aggregating

# aggregating= (value) ⇒对象(只写)

将属性聚合

参数:

  • 属性聚合所要设置的值。


16
17
18
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 16

def aggregating=()
  @aggregating = 
end

# 管道对象(只读)

返回属性管道的值。


13
14
15
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13

def 管道
  管道
end

# 管道聚合管道。 (聚合管道。)⇒对象(只读)


13
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 13

attr_reader :管道

实例方法详细信息

#正在聚合?true | false

可聚合对象是否进入聚合状态。 即,点仅允许聚合操作。

例子:

可聚合吗?

aggregable.aggregating?

返回:

  • ( true | false )

    如果可聚合对象正在聚合。

[查看源代码]

25
26
27
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 25

def 正在聚合?
  !!@aggregating
end

# 群组 (operation) ⇒ Aggregable

将群组($ 群组) 操作添加到聚合管道。

例子:

添加详细的群组操作。

aggregable.group(count: { "$sum" => 1 }, max: { "$max" => "likes" })

使用符号快捷方式添加群组操作。

aggregable.group(:count.sum => 1, :max.max => "likes")

参数:

  • 操作 (哈希)

    群组操作。

返回:

[查看源代码]

40
41
42
43
44
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 40

def GROUP(操作)
  聚合(操作) do |管道|
    管道.GROUP(操作)
  end
end

# 项目 (operation = nil) ⇒可聚合

将投影 ($project) 添加到聚合管道。

例子:

向管道添加投影。

aggregable.project(author: 1, name: 0)

参数:

  • 操作 哈希 (默认为: nil

    要进行的投影。

返回:

[查看源代码]

62
63
64
65
66
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 62

def 项目(操作 = nil)
  聚合(操作) do |管道|
    管道.项目(操作)
  end
end

# unwind (字段) ⇒可聚合

将展开 ($unwind) 添加到聚合管道。

例子:

为管道添加展开。

aggregable.unwind(:field)

参数:

  • 字段 ( string | Symbol )

    要展开的字段的名称。

返回:

[查看源代码]

76
77
78
79
80
# File 'lib/mongoid/criteria/queryable/aggregable.rb', line 76

def Unwind(字段)
  聚合(字段) do |管道|
    管道.Unwind(字段)
  end
end