模块:Mongo::Collection::View::Readable

包含在:
Mongo::Collection::View
定义于:
lib/ Mongo/ 集合/view/可读.rb

Overview

定义集合视图的读取相关行为。

由于:

  • 2.0.0

实例方法摘要折叠

实例方法详细信息

#aggregate (管道, options = {}) ⇒聚合

在集合视图上执行聚合。

例子:

聚合文档。

view.aggregate([
  { "$group" => { "_id" => "$city", "tpop" => { "$sum" => "$pop" }}}
])

参数:

  • 管道 ( Array<Hash> )

    聚合管道。

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

    聚合选项。

选项哈希 ( options ):

  • :allow_disk_use ( true , false )

    如果在聚合期间允许使用磁盘,则设置为 true。

  • :batch_size 整数

    批次中要返回的文档数量。

  • :bypass_document_validation ( true , false )

    是否跳过文档级验证。

  • :collation 哈希

    要使用的排序规则。

  • :comment 对象

    用户提供的待附加到该命令的注释。

  • :hint string

    用于该聚合的索引。

  • :let 哈希

    映射要在管道中使用的变量。 有关详细信息,请参阅服务器文档。

  • :max_time_ms 整数

    允许聚合运行的最长时间(以毫秒为单位)。 此选项已弃用,请改用 :timeout_ms。

  • :session 会话

    要使用的会话。

  • :timeout_ms 整数

    操作超时(以毫秒为单位)。 必须是非负整数。 0 的显式值表示无限。 未设置默认值,这意味着该值是从集合、数据库或客户端继承的。

返回:

  • (聚合)

    聚合对象。

由于:

  • 2.0.0



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ Mongo/ 集合/view/可读.rb', line 61

def 聚合(管道, 选项 = {})
  选项 = @options.合并(merge)(选项) 除非 mongo.broken_view_options
  聚合 = 聚合(Aggregation).new(self, 管道, 选项)

  # 因为 $merge 和 $out 管道阶段将文档写入
  # 集合,执行时需要清除缓存。
  #
  # 选择清除整个缓存而不是一个命名空间,因为
  # $out 和 $merge 阶段不必写入同一命名空间
  # 在其上执行聚合。
  查询缓存.清除 if 聚合.写入?

  聚合
end

# allow_disk_use查看

允许服务器在执行查找操作时将临时数据写入磁盘。

返回:

  • ( View )

    新视图。

由于:

  • 2.0.0



80
81
82
# File 'lib/ Mongo/ 集合/view/可读.rb', line 80

def allow_disk_use
  配置(:allow_disk_use, true)
end

# allow_partial_results查看

如果某些分片关闭,则允许查询获取部分结果。

例子:

允许部分结果。

view.allow_partial_results

返回:

  • ( View )

    新视图。

由于:

  • 2.0.0



92
93
94
# File 'lib/ Mongo/ 集合/view/可读.rb', line 92

def allow_partial_results
  配置(:allow_partial_results, true)
end

# await_data查看

让查询的游标保持打开状态并等待数据。

例子:

等待游标上的数据。

view.await_data

返回:

  • ( View )

    新视图。

由于:

  • 2.0.0



104
105
106
# File 'lib/ Mongo/ 集合/view/可读.rb', line 104

def await_data
  配置(:await_data, true)
end

# batch_size (batch_size = nil) ⇒ Integer , View

注意:

指定1或负数类似于设置限制。

MongoDB批处理结果中返回的文档数量。

例子:

设置批处理大小。

view.batch_size(5)

参数:

  • batch_size 整数 (默认为: nil

    批处理结果的大小。

返回:

  • ( Integer , View )

    batch_size 值或新的View

由于:

  • 2.0.0



121
122
123
# File 'lib/ Mongo/ 集合/view/可读.rb', line 121

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

# comment (comment = nil) ⇒ string , View

注意:

将 profilingLevel 设置为2 ,评论将与查询一起记录在配置文件集合中。

将注释与查询关联。

例子:

添加评论。

view.comment('slow query')

参数:

  • comment 对象 (默认为: nil

    与查询相关的注释。

返回:

  • ( string , View )

    注释或新的View

由于:

  • 2.0.0



139
140
141
# File 'lib/ Mongo/ 集合/view/可读.rb', line 139

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

# count (opts = {}) ⇒整数

已弃用。

请改用 #count_documents 或 #estimated_document_count。 但请注意,切换到 #count_documents 时需要替换以下操作符:

* $where should be replaced with $expr (only works on 3.6+)
* $near should be replaced with $geoWithin with $center
* $nearSphere should be replaced with $geoWithin with $centerSphere

获取集合中匹配文档的计数。

例子:

获取集合中的文档数。

collection_view.count

参数:

  • opts 哈希 (默认为: {}

    操作选项。

  • 选项 (哈希)

    一组可自定义的选项

选项哈希 ( opts ):

  • :skip 整数

    要跳过的文档数量。

  • :hint 哈希

    覆盖默认索引选择并强制 MongoDB 使用特定索引进行查询。

  • :limit 整数

    要计数的最大Docs数。

  • :max_time_ms 整数

    允许命令运行的最长时间。

  • :read 哈希

    读取偏好(read preference)选项。

  • :collation 哈希

    要使用的排序规则。

  • :session ( Mongo::Session )

    用于操作的会话。

  • :comment 对象

    用户提供的待附加到该命令的注释。

返回:

  • ( Integer )

    文档计数。

由于:

  • 2.0.0



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'lib/ Mongo/ 集合/view/可读.rb', line 175

def 数数(opts = {})
  opts = @options.合并(merge)(opts) 除非 mongo.broken_view_options
  cmd = { :count => 集合.名称, :query => 筛选器 }
  cmd[:skip] = opts[:skip] if opts[:skip]
  cmd[:hint] = opts[:hint] if opts[:hint]
  cmd[:limit] = opts[:limit] if opts[:limit]
  if read_concern
    cmd[:readConcern] = 选项::映射器.transform_values_to_strings(
      read_concern)
  end
  cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
  mongo::Lint.validate_underscore_read_preference(opts[:read])
  read_pref = opts[:read] || read_preference
  选择器 = ServerSelector.获取(read_pref || server_selector)
  with_session(opts) do |会话|
    上下文 = 操作::上下文.new(
      客户端: 客户端,
      会话: 会话,
      operation_timeups: operation_timeups(opts)
    )
    read_with_retry(会话, 选择器, 上下文) do |server|
      操作::数数.new(
        选择器: cmd,
        db_name: database.名称,
        选项: {:limit => -1},
        读取: read_pref,
        会话: 会话,
        # 由于某种原因,排序规则在历史上被接受为
        # string key. 请注意,这不会被记录为有效用法。
        排序规则: opts[:collation] || opts[' collation '] || 排序规则,
        comment: opts[:comment],
      ).执行(
        server,
        上下文: 上下文
      )
    end.n.to_i
  end
end

# count_documents (opts = {}) ⇒ Integer

获取集合中匹配文档的计数。

例子:

获取集合中的文档数。

collection_view.count

参数:

  • opts 哈希 (默认为: {}

    操作选项。

  • 运维 (哈希)

    一组可自定义的选项

  • 选项 (哈希)

    一组可自定义的选项

选项哈希 ( opts ):

  • :skip 整数

    要跳过的文档数量。

  • :hint 哈希

    覆盖默认索引选择并强制MongoDB使用特定索引进行查询。 需要服务器版本3.6 +。

  • :limit 整数

    要计数的最大Docs数。

  • :max_time_ms 整数

    允许命令运行的最长时间。 此选项已弃用,请改用 :timeout_ms。

  • :read 哈希

    读取偏好(read preference)选项。

  • :collation 哈希

    要使用的排序规则。

  • :session ( Mongo::Session )

    用于操作的会话。

返回:

  • ( Integer )

    文档计数。

由于:

  • 2.6.0



241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'lib/ Mongo/ 集合/view/可读.rb', line 241

def count_documents(opts = {})
  opts = @options.合并(merge)(opts) 除非 mongo.broken_view_options
  管道 = [:'$match' => 筛选器]
  管道 << { :'$skip' => opts[:skip] } if opts[:skip]
  管道 << { :'$limit' => opts[:limit] } if opts[:limit]
  管道 << { :'$group' => { _id: 1, n: { :'$sum' => 1 } } }

  opts = opts.slice(:hint, :max_time_ms, :read, :collation, :session, :comment, :timeout_ms)
  opts[:collation] ||= 排序规则

  first = 聚合(管道, opts).first
  return 0 除非 first
  first['n'].to_i
end

# cursor_type (type = nil) ⇒ :tailable , ...

要使用的游标类型。 可以是 :tailable 或 :tailable_await。

例子:

设置游标类型。

view.cursor_type(:tailable)

参数:

  • 类型 ( :tailable , :tailable_await ) (默认为: nil

    游标类型。

返回:

  • ( :tailable , :tailable_await , View )

    游标类型设置或新的View

由于:

  • 2.3.0



660
661
662
# File 'lib/ Mongo/ 集合/view/可读.rb', line 660

def cursor_type(类型 = nil)
  配置(:cursor_type, 类型)
end

# distinct (field_name, opts = {}) ⇒ Array<Object>

获取特定字段的非重复值列表。

例子:

获取不同的值。

collection_view.distinct('name')

参数:

  • field_name ( string , Symbol )

    字段的名称。

  • opts 哈希 (默认为: {}

    distinct 命令的选项。

  • 选项 (哈希)

    一组可自定义的选项

选项哈希 ( opts ):

  • :max_time_ms 整数

    允许命令运行的最长时间。

  • :read 哈希

    读取偏好(read preference)选项。

  • :collation 哈希

    要使用的排序规则。

返回:

  • ( Array<Object> )

    非重复值列表。

由于:

  • 2.0.0



343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
# File 'lib/ Mongo/ 集合/view/可读.rb', line 343

def distinct(field_name, opts = {})
  if field_name.nil?
    提高 ArgumentError, '用于非重复操作的字段名称不得为 nil '
  end
  opts = @options.合并(merge)(opts) 除非 mongo.broken_view_options
  cmd = { :distinct => 集合.名称,
          :key => field_name.to_s,
          :query => 筛选器, }
  cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
  if read_concern
    cmd[:readConcern] = 选项::映射器.transform_values_to_strings(
      read_concern)
  end
  mongo::Lint.validate_underscore_read_preference(opts[:read])
  read_pref = opts[:read] || read_preference
  选择器 = ServerSelector.获取(read_pref || server_selector)
  with_session(opts) do |会话|
    上下文 = 操作::上下文.new(
      客户端: 客户端,
      会话: 会话,
      operation_timeups: operation_timeups(opts)
    )
    read_with_retry(会话, 选择器, 上下文) do |server|
      操作::distinct.new(
        选择器: cmd,
        db_name: database.名称,
        选项: {:limit => -1},
        读取: read_pref,
        会话: 会话,
        comment: opts[:comment],
        # 由于某种原因,排序规则在历史上被接受为
        # string key. 请注意,这不会被记录为有效用法。
        排序规则: opts[:collation] || opts[' collation '] || 排序规则,
      ).执行(
        server,
        上下文: 上下文
      )
    end.first[' values ']
  end
end

#estimated_document_count (opts = {}) ⇒ Integer

使用集合元数据获取集合中文档的估计数量。

例子:

获取集合中的文档数。

collection_view.estimated_document_count

参数:

  • opts 哈希 (默认为: {}

    操作选项。

  • 选项 (哈希)

    一组可自定义的选项

选项哈希 ( opts ):

  • :max_time_ms 整数

    允许命令运行的最长时间。

  • :read 哈希

    读取偏好(read preference)选项。

  • :comment 对象

    用户提供的待附加到该命令的注释。

返回:

  • ( Integer )

    文档计数。

由于:

  • 2.6.0



276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
# File 'lib/ Mongo/ 集合/view/可读.rb', line 276

def estimated_document_count(opts = {})
  除非 查看.筛选器.空?
    提高 ArgumentError, 使用筛选器查询时无法调用estimated_document_count 
  end

  %i[limit 跳过]. do |opt|
    if 选项.键?(opt) || opts.键?(opt)
      提高 ArgumentError, " 使用 #{ opt} 进行查询时,无法调用estimated_document_count "
    end
  end

  opts = @options.合并(merge)(opts) 除非 mongo.broken_view_options
  mongo::Lint.validate_underscore_read_preference(opts[:read])
  read_pref = opts[:read] || read_preference
  选择器 = ServerSelector.获取(read_pref || server_selector)
  with_session(opts) do |会话|
    上下文 = 操作::上下文.new(
      客户端: 客户端,
      会话: 会话,
      operation_timeups: operation_timeups(opts)
    )
    read_with_retry(会话, 选择器, 上下文) do |server|
      cmd = { 计数: 集合.名称 }
      cmd[:maxTimeMS] = opts[:max_time_ms] if opts[:max_time_ms]
      if read_concern
        cmd[:readConcern] = 选项::映射器.transform_values_to_strings(read_concern)
      end
      结果 = 操作::数数.new(
        选择器: cmd,
        db_name: database.名称,
        读取: read_pref,
        会话: 会话,
        comment: opts[:comment],
      ).执行(server, 上下文: 上下文)
      结果.n.to_i
    end
  end
救援 错误::OperationFailure::家庭情况 => 排除
  if 排除.代码 == 26
    # NamespaceNotFound
    # 这应该只发生在聚合管道路径上
    #(服务器4.9 +)。 以前的服务器应返回0 (表示不存在)
    # collections.
    0
  else
    提高
  end
end

#hint (hint = nil) ⇒ Hash , View

MongoDB 将强制用于查询的索引。

例子:

设置索引提示。

view.hint(name: 1)

参数:

  • 提示 哈希 (默认为: nil

    用于查询的索引。

返回:

  • 哈希视图

    提示或新的View

由于:

  • 2.0.0



394
395
396
# File 'lib/ Mongo/ 集合/view/可读.rb', line 394

def 提示(提示 = nil)
  配置(:hint, 提示)
end

#limit(limit = nil) ⇒ Integer, View

从查询中返回的最大Docs数。

例子:

设置限制。

view.limit(5)

参数:

  • limit 整数 (默认为: nil

    要返回的Docs数量。

返回:

  • ( Integer , View )

    限制或新的View

由于:

  • 2.0.0



408
409
410
# File 'lib/ Mongo/ 集合/view/可读.rb', line 408

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

# map_reduce (map, reduce, options = {}) ⇒ MapReduce

在集合视图上执行 map/reduce 操作。

例子:

执行 map/reduce。

view.map_reduce(map, reduce)

参数:

  • map ( string )

    地图JavaScript函数。

  • 化简(reduce) ( string )

    reduce JavaScript函数。

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

    map/reduce 选项。

返回:

由于:

  • 2.0.0



424
425
426
# File 'lib/ Mongo/ 集合/view/可读.rb', line 424

def map_reduce(map, 化简(reduce), 选项 = {})
  MapReduce.new(self, map, 化简(reduce), @options.合并(merge)(选项))
end

# max_await_time_ms (max = nil) ⇒ Integer , View

在游标上处理获取更多操作的累积时间限制(以毫秒为单位)。

例子:

设置最大等待时间(毫秒)值。

view.max_await_time_ms(500)

参数:

  • Max 整数 (默认为: nil

    最长时间(以毫秒为单位)。

返回:

  • ( Integer , View )

    最大等待时间(毫秒)值或新的View

由于:

  • 2.1.0



632
633
634
# File 'lib/ Mongo/ 集合/view/可读.rb', line 632

def max_await_time_ms(Max = nil)
  配置(:max_await_time_ms, Max)
end

# max_scan (value = nil) ⇒ Integer , View

已弃用。

从 MongoDB 服务器版本4.0开始,此选项已弃用。

设置要扫描的最大文档数。

例子:

设置最大扫描值。

view.max_scan(1000)

参数:

  • 整数 (默认为: nil

    要扫描的最大数量。

返回:

  • ( Integer , View )

    值或新的View

由于:

  • 2.0.0



441
442
443
# File 'lib/ Mongo/ 集合/view/可读.rb', line 441

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

# max_time_ms (max = nil) ⇒ Integer , View

对游标进行处理操作的累积时间限制(以毫秒为单位)。

例子:

设置最长时间(毫秒)值。

view.max_time_ms(500)

参数:

  • Max 整数 (默认为: nil

    最长时间(以毫秒为单位)。

返回:

  • ( Integer , View )

    最长时间毫秒值或新的View

由于:

  • 2.1.0



646
647
648
# File 'lib/ Mongo/ 集合/view/可读.rb', line 646

def max_time_ms(Max = nil)
  配置(:max_time_ms, Max)
end

# max_value (value = nil) ⇒ Hash , View

将最大值设置为Atlas Search 。

例子:

设置最大值。

view.max_value(_id: 1)

参数:

  • 哈希 (默认为: nil

    最大值字段和值。

返回:

  • 哈希视图

    值或新的View

由于:

  • 2.1.0



455
456
457
# File 'lib/ Mongo/ 集合/view/可读.rb', line 455

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

# min_value (value = nil) ⇒ Hash , View

将最小值设置为搜索。

例子:

设置最小值。

view.min_value(_id: 1)

参数:

  • 哈希 (默认为: nil

    最小字段和值。

返回:

  • 哈希视图

    值或新的View

由于:

  • 2.1.0



469
470
471
# File 'lib/ Mongo/ 集合/view/可读.rb', line 469

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

#modifiers(doc = nil) ⇒ Hash, View

如果不带参数或使用 nil 参数调用,则返回当前视图的传统 (OP_QUERY)服务器修饰符。 如果使用非 nil 参数(必须是哈希或子类)调用,则将提供的修饰符合并到当前视图中。 输入哈希中允许使用string键和符号键。

例子:

设置修饰符文档。

view.modifiers(:$orderby => Mongo::Index::ASCENDING)

参数:

  • doc 哈希 (默认为: nil

    修饰符文档。

返回:

  • 哈希视图

    修饰符文档或新的View

由于:

  • 2.1.0



613
614
615
616
617
618
619
# File 'lib/ Mongo/ 集合/view/可读.rb', line 613

def modifiers(doc = nil)
  if doc.nil?
    操作::find::生成器::Modifiers.map_server_modifiers(选项)
  else
    new(选项.合并(merge)(操作::find::生成器::Modifiers.map_driver_options(BSON::文档.new(doc))))
  end
end

# no_cursor_timeout查看

服务器通常会在不活动期( 10分钟)后使空闲游标超时,以防止过度使用内存。 设置此选项可防止出现这种情况。

例子:

将游标设置为不超时。

view.no_cursor_timeout

返回:

  • ( View )

    新视图。

由于:

  • 2.0.0



482
483
484
# File 'lib/ Mongo/ 集合/view/可读.rb', line 482

def no_cursor_timeout
  配置(:no_cursor_timeout, true)
end

#parallel_scan (cursor_count, options = {}) ⇒ 对象

由于:

  • 2.0.0



702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
# File 'lib/ Mongo/ 集合/view/可读.rb', line 702

def parallel_scan(cursor_count, 选项 = {})
  if 选项[:session]
    # 该会话稍后将被 +options+ 中的会话覆盖。
    会话 = 客户端.get_session(@options)
  else
    会话 = nil
  end
  server = server_selector.select_server(集群, nil, 会话)
  spec = {
    coll_name: 集合.名称,
    db_name: database.名称,
    cursor_count: cursor_count,
    read_concern: read_concern,
    会话: 会话,
  }.update(选项)
  会话 = spec[:session]
  op = 操作::ParallelScan.new(spec)
  # 请注意,上下文对象不应重复用于后续
  # GetMore 操作。
  上下文 = 操作::上下文.new(客户端: 客户端, 会话: 会话)
  结果 = op.执行(server, 上下文: 上下文)
  结果.cursor_id.map do |cursor_id|
    spec = {
      cursor_id: cursor_id,
      coll_name: 集合.名称,
      db_name: database.名称,
      会话: 会话,
      batch_size: batch_size,
      to_return: 0,
      # max_time_ms 没有在这里传递,我认为是故意的?
    }
    op = 操作::getMore.new(spec)
    上下文 = 操作::上下文.new(
      客户端: 客户端,
      会话: 会话,
      connection_global_id: 结果.connection_global_id,
    )
    结果 = if server.load_balancer?
               # 当游标耗尽时,将签入连接。
               连接 = server..check_out(上下文: 上下文)
               op.execute_with_connection(连接, 上下文: 上下文)
             else
               op.执行(server, 上下文: 上下文)
             end
    Cursor.new(self, 结果, server, 会话: 会话)
  end
end

投影 (文档 = nil) ⇒ Hash , View

注意:

值为0会从文档中排除字段。 值为1时会将其包含在内。 除_id值外,所有值必须均为0或均为1 。 默认包含_id字段。 必须明确将其排除。

结果设立的每个文档要包含或排除的字段。

例子:

设置要包含或排除的字段。

view.projection(name: 1)

参数:

  • 文档 哈希 (默认为: nil

    字段和1或0 ,以包含或排除该字段。

返回:

  • 哈希视图

    字段或新的View

由于:

  • 2.0.0



500
501
502
503
# File 'lib/ Mongo/ 集合/view/可读.rb', line 500

def 投影(文档 = nil)
  validate_doc!(文档) if 文档
  配置(:projection, 文档)
end

# read (value = nil) ⇒符号,视图

注意:

如果未为查询指定任何内容,则将使用集合的读取偏好(read preference)。

用于查询的读取偏好。

参数:

  • 哈希 (默认为: nil

    用于查询的读取偏好模式。

返回:

由于:

  • 2.0.0



516
517
518
519
# File 'lib/ Mongo/ 集合/view/可读.rb', line 516

def ( = nil)
  return read_preference if .nil?
  配置(:read, )
end

# read_concern对象

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

由于:

  • 2.0.0



674
675
676
677
678
679
680
# File 'lib/ Mongo/ 集合/view/可读.rb', line 674

def read_concern
  if 选项[:session] && 选项[:session].in_transaction?
    选项[:session].发送(:txn_read_concern) || 集合.客户端.read_concern
  else
    集合.read_concern
  end
end

# read_preference对象

此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。

由于:

  • 2.0.0



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
# File 'lib/ Mongo/ 集合/view/可读.rb', line 683

def read_preference
  @read_preference ||= 开始
    # 操作读取偏好(read preference)始终受到尊重,并且具有
    # 最高优先级。 如果处于ACID 事务中,我们会查看
    #ACID 事务读取偏好(read preference),默认为客户端,忽略
    #集合读取偏好(read preference)。 如果我们没有处于ACID 事务状态
    # 查看集合读取偏好(read preference),默认为客户端。
    rp = if 选项[:read]
      选项[:read]
    elsif 选项[:session] && 选项[:session].in_transaction?
      选项[:session].txn_read_preference || 集合.客户端.read_preference
    else
      集合.read_preference
    end
    Lint.validate_underscore_read_preference(rp)
    rp
  end
end

# return_key (value = nil) ⇒ true , ...

设置是否仅返回索引字段。

例子:

设置返回键值。

view.return_key(true)

参数:

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

    返回键值。

返回:

  • ( true , false , View )

    值或新的View

由于:

  • 2.1.0



531
532
533
# File 'lib/ Mongo/ 集合/view/可读.rb', line 531

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

# show_disk_loc (value = nil) ⇒ true , ...也称为: show_record_id

设置是否应显示每个文档的磁盘位置。

例子:

设置显示磁盘位置选项。

view.show_disk_loc(true)

参数:

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

    字段的值。

返回:

  • ( true , false , View )

    该值或新的View

由于:

  • 2.0.0



546
547
548
# File 'lib/ Mongo/ 集合/view/可读.rb', line 546

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

# skip (number = nil) ⇒ Integer , View

返回结果之前要跳过的Docs数。

例子:

设置要跳过的数字。

view.skip(10)

参数:

  • 数字 整数 (默认为: nil

    要跳过的Docs数量。

返回:

  • ( Integer , View )

    跳过值或新的View

由于:

  • 2.0.0



562
563
564
# File 'lib/ Mongo/ 集合/view/可读.rb', line 562

def 跳过(数字 = nil)
  配置(:skip, 数字)
end

# 快照 (value = nil) ⇒对象

已弃用。

从 MongoDB 服务器版本4.0开始,此选项已弃用。

注意:

设立为 true 时,可防止文档多次返回。

设置视图的快照值。

例子:

设置快照值。

view.snapshot(true)

参数:

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

    快照值。

由于:

  • 2.0.0



580
581
582
# File 'lib/ Mongo/ 集合/view/可读.rb', line 580

def snapshot( = nil)
  配置(:快照, )
end

# sort (spec = nil) ⇒ Hash , View

对结果设立进行排序的键和方向对。

例子:

设置排序条件

view.sort(name: -1)

参数:

  • spec 哈希 (默认为: nil

    排序依据的属性和方向。

返回:

  • 哈希视图

    排序设置或新的View

由于:

  • 2.0.0



595
596
597
# File 'lib/ Mongo/ 集合/view/可读.rb', line 595

def sort(spec = nil)
  配置(:sort, spec)
end

#timeout_ms(timeout_ms = nil) ⇒ Integer, View

每次操作的超时时间(以毫秒为单位)。 必须为正整数。

参数:

  • timeout_ms 整数 (默认为: nil

    超时值。

返回:

  • ( Integer , View )

    timeout_ms 值或新的 View

由于:

  • 2.0.0



669
670
671
# File 'lib/ Mongo/ 集合/view/可读.rb', line 669

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