类:Mongo::Operation::Update::BulkResult Private

继承:
结果
  • 对象
显示全部
包括:
可聚合
定义于:
lib/ Mongo/operation/ 更新/bulk_result.rb

Overview

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

定义更新结果作为批量写入的一部分发送时的自定义行为。

由于:

  • 2.0.0

常量摘要折叠

已修改 =

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

结果中已修改Docs字段的数量。

由于:

  • 2.0.0

'nModified'
UPSERTED =

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

结果中更新或插入的Docs字段。

由于:

  • 2.0.0

'更新或插入'

从Result继承的常量

Result::CURSOR 、 Result::CURSOR_ID 、 Result::FIRST_BATCH 、 Result::N 、 Result::NAMESPACE 、 Result::NEXT_BATCH 、 Result::OK 、 Result::RESULT

实例属性摘要

从Result继承的属性

#connection 、 #connection_description 、 #connection_global_id 、 #context 、 #replies

实例方法摘要折叠

从Result继承的方法

#acknowledged?, #base_backoff_ms, #cluster_time, #cursor_id, #documents, #each, #error, #initialize, #inspect, #labels, 命名空间, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #成功?, #topology_version, #validate!, #write_concern_error?, #wred_count

构造函数详情

该类从Mongo::Operation::Result继承了一个构造函数

实例方法详细信息

# n_matched ⇒整数

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

获取匹配的文档数。

例子:

获取匹配的计数。

result.n_matched

返回:

  • ( Integer ) —

    匹配的文档数量。

由于:

  • 2.0.0



64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ Mongo/operation/ 更新/bulk_result.rb', line 64

def n_matched
  return 0 除非 已确认?

  @replies.化简(reduce)(0) do |n, 回复|
    if upsert?(回复)
      回复.文档.first[N] - n_upserted
    elsif 回复.文档.first[N]
      n + 回复.文档.first[N]
    else
      n
    end
  end
end

# n_modified ⇒整数

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

获取已修改的文档数。

例子:

获取修改后的计数。

result.n_modified

返回:

  • ( Integer ) —

    修改的文档数量。

由于:

  • 2.0.0



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/ Mongo/operation/ 更新/bulk_result.rb', line 86

def n_modified
  return 0 除非 已确认?

  @replies.化简(reduce)(0) do |n, 回复|
    if n && 回复.文档.first[MODIFIED]
      n + 回复.文档.first[MODIFIED]
    else
      0
    end
  end
end

# n_upserted ⇒整数

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

获取已更新或插入的文档数。

例子:

获取更新或插入的计数。

result.n_upserted

返回:

  • ( Integer ) —

    更新或插入的文档数量。

由于:

  • 2.0.0



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/ Mongo/operation/ 更新/bulk_result.rb', line 44

def n_upserted
  return 0 除非 已确认?

  @replies.化简(reduce)(0) do |n, 回复|
    if upsert?(回复)
      n + 回复.文档.first[UPSERTED].size
    else
      n
    end
  end
end

# upserted ⇒ Array<BSON::Document>

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

获取更新或插入的文档。

例子:

获取更新或插入的文档。

result.upserted

返回:

  • ( Array<BSON::Document> ) —

    更新或插入的文档信息

由于:

  • 2.1.0



106
107
108
109
110
111
112
113
114
115
# File 'lib/ Mongo/operation/ 更新/bulk_result.rb', line 106

def 更新或插入
  return [] 除非 已确认?

  @replies.化简(reduce)([]) do |id, 回复|
    if (upserted_id = 回复.文档.first[UPSERTED])
      id += upserted_id
    end
    id
  end
end