类:Mongoid::Contextual::None

继承:
对象
  • 对象
显示全部
包括:
Enumerable、 Aggregable::NoneQueryable
定义于:
lib/mongoid/contextual/none.rb

Overview

用于对 null设立执行批量查询和持久性操作的 Context对象。 该类的方法接口与 Mongoid::Contextual::Mongo一致。

实例属性摘要折叠

Queryable中包含的属性

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

实例方法摘要折叠

Queryable中包含的方法

#blank?

Aggregable::None中包含的方法

#aggregates#avg#min#sum

构造函数详情

#initialize (criteria) ⇒

创建新的 null 上下文。

例子:

创建新上下文。

Null.new(criteria)

参数:



120
121
122
# File 'lib/mongoid/contextual/none.rb', line 120

def 初始化(条件)
  @criteria, @klass = 条件, 条件.klass
end

实例属性详细信息

# 个条件对象(只读)

返回属性条件的值。



17
18
19
# File 'lib/mongoid/contextual/none.rb', line 17

def 条件
  @criteria
end

# klass对象(只读)

返回属性 klass 的值。



17
18
19
# File 'lib/mongoid/contextual/none.rb', line 17

def klass
  @klass
end

实例方法详细信息

# == (other) ⇒ true | false

检查上下文是否等于其他对象。

例子:

检查相等性。

context == []

参数:

  • 其他 ( Array )

    另一个大量。

返回:

  • ( true | false )

    如果对象相等。



27
28
29
# File 'lib/mongoid/contextual/none.rb', line 27

def ==(其他)
  其他.is_a?()
end

# distinct (_field) ⇒数组

获取 null 上下文中的非重复字段值。

例子:

获取 null 上下文中的非重复值。

context.distinct(:name)

参数:

  • _field ( string | Symbol )

    字段的名称。

返回:

  • ( Array )

    一个空数组。



39
40
41
# File 'lib/mongoid/contextual/none.rb', line 39

def distinct(_field)
  []
end

#each枚举器

遍历 null 上下文。 在这种情况下,没有要迭代的文档。

例子:

遍历 null 上下文。

context.each do |doc|
  puts doc.name
end

返回:

  • (枚举器)

    枚举器。



52
53
54
55
56
57
58
59
# File 'lib/mongoid/contextual/none.rb', line 52

def 
  if block_given?
    []. { |doc| 产量(doc) }
    self
  else
    to_enum
  end
end

#是否存在? (id_or_conditions = :none) ⇒ false

该上下文是否存在任何文档。

例子:

null 上下文中是否存在任何文档。

context.exists?

给定 _id 是否存在任何文档。

context.exists?(BSON::ObjectId(...))

在给定条件下是否存在任何文档。

context.exists?(name: "...")

参数:

  • id_or_conditions 哈希 | 对象 | false (默认为: :none

    要搜索的_id 、条件哈希、nil 或 false。

返回:

  • ( false )

    始终为 false。



76
# File 'lib/mongoid/contextual/none.rb', line 76

def 存在吗?(id_or_conditions = : none) false end

#第五个nil

始终返回零。

例子:

在 null 上下文中获取第五个文档。

context.fifth

返回:

  • ( nil )

    始终为零。



256
257
258
# File 'lib/mongoid/contextual/none.rb', line 256

def 第五
  nil
end

#第五!对象

始终引发错误。

例子:

在 null 上下文中获取第五个文档。

context.fifth!

引发:



266
267
268
# File 'lib/mongoid/contextual/none.rb', line 266

def 第五!
  Raise_document_not_Found_error
end

# first (limit = nil) ⇒ [] | nil也称为: find_firstone

始终返回零。

例子:

获取空上下文中的第一个文档。

context.first

参数:

  • limit 整数 (默认为: nil

    要返回的文档数量。

返回:

  • ([] | nil)

    空数组或 nil。



132
133
134
# File 'lib/mongoid/contextual/none.rb', line 132

def first(limit = nil)
  [] 除非 limit.nil?
end

# first!对象

始终引发错误。

例子:

获取空上下文中的第一个文档。

context.first!

引发:



142
143
144
# File 'lib/mongoid/contextual/none.rb', line 142

def 首先!
  Raise_document_not_Found_error
end

#fourthnil

始终返回零。

例子:

在 null 上下文中获取第四个文档。

context.fourth

返回:

  • ( nil )

    始终为零。



236
237
238
# File 'lib/mongoid/contextual/none.rb', line 236

def 第四
  nil
end

#fourth!对象

始终引发错误。

例子:

在 null 上下文中获取第四个文档。

context.fourth!

引发:



246
247
248
# File 'lib/mongoid/contextual/none.rb', line 246

def 第四!
  Raise_document_not_Found_error
end

#last(limit = nil) ⇒ [] | nil

始终返回零。

例子:

获取 null 上下文中的最后一个文档。

context.last

参数:

  • limit 整数 (默认为: nil

    要返回的文档数量。

返回:

  • ([] | nil)

    空数组或 nil。



154
155
156
# File 'lib/mongoid/contextual/none.rb', line 154

def last(limit = nil)
  [] 除非 limit.nil?
end

# last!对象

始终引发错误。

例子:

获取 null 上下文中的最后一个文档。

context.last!

引发:



164
165
166
# File 'lib/mongoid/contextual/none.rb', line 164

def last!
  Raise_document_not_Found_error
end

# lengthInteger也称为:大小

始终返回零。

例子:

获取 null 上下文的长度。

context.length

返回:

  • ( Integer )

    始终为零。



316
317
318
# File 'lib/mongoid/contextual/none.rb', line 316

def 长度
  条目.长度
end

# pick (*_fields) ⇒ nil

在 null 上下文中选取字段值。

例子:

获取 null 上下文的值。

context.pick(:name)

参数:

  • *_fields ( [ string | Symbol ]... )

    要选择的字段。

返回:

  • ( nil )

    始终返回 nil。



98
99
100
# File 'lib/mongoid/contextual/none.rb', line 98

def pick(*_fields)
  nil
end

# pluck (*_fields) ⇒数组

在 null 上下文中提取字段值。

例子:

获取 null 上下文的值。

context.pluck(:name)

参数:

  • *_fields ( [ string | Symbol ]... )

    要提取的字段。

返回:

  • ( Array )

    一个空数组。



86
87
88
# File 'lib/mongoid/contextual/none.rb', line 86

def 采摘(*_fields)
  []
end

#secondnil

始终返回零。

例子:

在 null 上下文中获取第二个文档。

context.second

返回:

  • ( nil )

    始终为零。



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

def 
  nil
end

#秒!对象

始终引发错误。

例子:

在 null 上下文中获取第二个文档。

context.second!

引发:



206
207
208
# File 'lib/mongoid/contextual/none.rb', line 206

def 第二!
  Raise_document_not_Found_error
end

# Second_to_lastnil

始终返回零。

例子:

获取空上下文中的倒数第二个文档。

context.second_to_last

返回:

  • ( nil )

    始终为零。



276
277
278
# File 'lib/mongoid/contextual/none.rb', line 276

def Second_to_last
  nil
end

# Second_to_last!对象

始终引发错误。

例子:

获取空上下文中的倒数第二个文档。

context.second_to_last!

引发:



286
287
288
# File 'lib/mongoid/contextual/none.rb', line 286

def Second_to_last!
  Raise_document_not_Found_error
end

#take(limit = nil) ⇒ [] | nil

返回 nil 或空数组。

例子:

在空上下文中获取文档。

context.take

参数:

  • limit ( Integer | nil ) (默认为: nil

    要获取的文档数量或为零。

返回:

  • ([] | nil)

    空数组或 nil。



176
177
178
# File 'lib/mongoid/contextual/none.rb', line 176

def 采取(limit = nil)
  limit ? [] : nil
end

#take!对象

始终引发错误。

例子:

在空上下文中获取文档。

context.take!

引发:



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

def 采取!
  Raise_document_not_Found_error
end

#tally (_field) ⇒哈希

统计 null 上下文中的字段值。

例子:

获取 null 上下文的值。

context.tally(:name)

参数:

  • _field ( string | Symbol )

    要统计的字段。

返回:

  • (哈希)

    空哈希。



110
111
112
# File 'lib/mongoid/contextual/none.rb', line 110

def 计数(_field)
  {}
end

# Thirdnil

始终返回零。

例子:

在 null 上下文中获取第三个文档。

context.third

返回:

  • ( nil )

    始终为零。



216
217
218
# File 'lib/mongoid/contextual/none.rb', line 216

def 第三
  nil
end

# Third!对象

始终引发错误。

例子:

在 null 上下文中获取第三个文档。

context.third!

引发:



226
227
228
# File 'lib/mongoid/contextual/none.rb', line 226

def 第三!
  Raise_document_not_Found_error
end

# Third_to_lastnil

始终返回零。

例子:

在 null 上下文中获取倒数第三个文档。

context.third_to_last

返回:

  • ( nil )

    始终为零。



296
297
298
# File 'lib/mongoid/contextual/none.rb', line 296

def Third_to_last
  nil
end

# Third_to_last!对象

始终引发错误。

例子:

在 null 上下文中获取倒数第三个文档。

context.third_to_last!

引发:



306
307
308
# File 'lib/mongoid/contextual/none.rb', line 306

def Third_to_last!
  Raise_document_not_Found_error
end