类:Mongo::Operation::Insert::Result

继承:
结果
  • 对象
显示全部
定义于:
lib/ Mongo/operation/insert/result.rb

Overview

定义插入结果的自定义行为。

根据 CRUD 规范,报告插入的 ID 是可选的。 如果需要,可以稍后将其添加到此类中。

由于:

  • 2.0.0

常量摘要

Result继承的常量

Result::CURSORResult::CURSOR_IDResult::FIRST_BATCHResult::NResult::NAMESPACEResult::NEXT_BATCHResult::OKResult::RESULT

实例属性摘要折叠

Result继承的属性

#connection #connection_description #connection_global_id #context #replies

实例方法摘要折叠

Result继承的方法

#acknowledged? 、#cluster_time、 # cursor_id、#documents、# each 、# error # has_cursor_id ? #inspect #labels 、# namespace 、# ok? #operation_time #reply #returned_count #snapshot_timestamp #successful? #topology_version #validate! , #write_concern_error? , #liter_count

构造函数详情

#initialize (replies, connection_description, connection_global_id, ids, context: nil) 结果

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

初始化新结果。

例子:

实例化结果。

Result.new(replies, inserted_ids)

参数:

  • 回复 (Array<Protocol::Message> | nil)

    传输协议回复(如果有)。

  • connection_description ( Server::Description )

    MongoDB Server对执行此结果所属操作的服务器的描述。

  • connection_global_id ( Integer )

    执行此结果所属操作的连接的全局 ID。

  • id ( Array<Object> )

    已插入文档的 ID。

  • 上下文 (Operation::Context | nil) (默认为: nil

    生成此结果时处于活动状态的操作上下文。

由于:

  • 2.0.0

[查看源代码]

55
56
57
58
# File 'lib/ Mongo/operation/insert/result.rb', line 55

def 初始化(回复, connection_description, connection_global_id, id, 上下文: nil)
  (回复, connection_description, connection_global_id, 上下文: 上下文)
  @inserted_ids = id
end

实例属性详细信息

# Insert_Ids对象(只读)

获取插入文档的 ID。

由于:

  • 2.0.0


35
36
37
# File 'lib/ Mongo/operation/insert/result.rb', line 35

def Inserted_Ids
  @inserted_ids
end

实例方法详细信息

# bulk_result对象

由于:

  • 2.0.0

[查看源代码]

74
75
76
# File 'lib/ Mongo/operation/insert/result.rb', line 74

def bulk_result
  BulkResult.new(@replies, connection_description, connection_global_id, @inserted_ids)
end

# Insert_id对象

获取插入的文档的 ID。

例子:

获取插入文档的 ID。

result.inserted_id

返回:

  • ( Object )

    插入文档的 ID。

由于:

  • 2.0.0

[查看源代码]

69
70
71
# File 'lib/ Mongo/operation/insert/result.rb', line 69

def Inserted_id
  Inserted_Ids.first
end