类:Mongo::Operation::Result
- 继承:
-
对象
- 对象
- Mongo::Operation::Result
- 扩展方式:
- 可转发
- 包括:
- 可枚举
- 定义于:
- lib/ Mongo/operation/result.rb 、
lib/ Mongo/operation/shared/result/aggregatable.rb、
lib/ Mongo/operation/shared/result/use_legacy_error_parser.rb
Overview
传输协议回复的结果包装器。
一个操作有零个或一个回复。 唯一产生零回复的操作是未确认的写入;所有其他操作都会产生一个回复。 此类提供了一个对象,即使操作未生成回复(在这种情况下假定已成功),也可以对其进行操作(例如,检查操作是否成功)。
直接已知子类
Aggregate::Result 、 CollectionsInfo::Result 、 Delete::BulkResult 、 Delete::Result 、 Explain::Result 、 Find::Result 、 GetMore::Result 、 Indexes::Result 、 Insert::BulkResult 、 Insert::Result 、 ListCollections::Result 、 MapReduce::Result 、 ParallelScan::Result 、 Update::BulkResult 、 Update::Result 、 UsersInfo::Result
在命名空间下定义
模块: Aggregatable , UseLegacyErrorParser
常量摘要折叠
- CURSOR =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
聚合中游标文档的字段名称。
' cursor '.冻结
- CURSOR_ID =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
游标文档中的游标 ID 字段。
' ID '.冻结
- FIRST_BATCH =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
游标第一批的字段名称。
' firstBatch '.冻结
- NEXT_BATCH =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
下一批游标的字段名称。
' nextBatch '.冻结
- NAMESPACE =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
游标文档中的命名空间字段。
' ns '.冻结
- N =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
写入中更新的文档数量。
'n'.冻结
- 确定 =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
结果中的 ok 状态字段。
' Ok '.冻结
- 结果 =
此常量是私有 API 的一部分。 应尽可能避免使用此常量,因为它将来可能会被删除或更改。
结果字段常量。
' result '.冻结
实例属性摘要折叠
- # connection ⇒ 对象 只读
-
# connection_description ⇒ Server::Description
只读
private
对该结果所属服务器执行操作的服务器描述。
-
# connection_global_id ⇒ 对象
只读
private
全局是针对此结果所针对的操作执行的连接的。
-
#context ⇒ Operation::Context | nil
只读
private
生成此结果时处于活动状态的操作上下文(如果有)。
-
#replies ⇒ Array<Protocol::Message>
只读
private
回复 包装的传输协议回复。
实例方法摘要折叠
-
#已确认? ⇒ true, false
结果是否已得到确认?
-
# cluster_time ⇒ ClusterTime | nil
获取服务器响应中报告的集群时间。
-
# cursor_id = "Integer"
private
如果响应得到确认,则获取游标 ID。
-
# 个documents ⇒ Array<BSON::Document>
获取结果中的文档。
-
#每个{|Each| ... } ⇒ 枚举器
遍历回复中的文档。
-
# error ⇒ Error::OperationFailure::Family
private
处理此结果期间将引发的(Error::OperationFailure::Family 的)异常实例。
-
# has_cursor_id? ⇒ true, false
private
结果是否包含 cursor_id。
-
#initialize (replies, connection_description = nil, connection_global_id = nil, context: nil, connection: nil) ⇒ 结果
构造函数
private
初始化新结果。
-
#检查⇒ string
获取结果的美观格式检查。
-
# labels ⇒ 数组
private
获取与结果关联的错误标签集。
-
#命名空间⇒ Nil
private
获取游标的命名空间。
-
#可以吗? ⇒ true, false
检查第一个文档的 ok 字段。
-
# operation_time ⇒ 对象 | nil
获取服务器响应中报告的 optime。
-
#reply ⇒ Protocol::Message
private
从结果中获取回复。
-
# returned_count ⇒ 整数
获取此批处理中服务器返回的文档数。
- # snapshot_timestamp ⇒ 对象
-
# 成功? ⇒ true, false
如果结果是命令,则确定是否成功。
-
# topology_version ⇒ TopologyVersion | nil
private
拓扑版本。
-
#validate! ⇒ Result
private
通过检查是否存在任何错误来验证结果。
-
# write_concern_error? ⇒ 布尔
private
操作是否因写关注错误而失败。
-
# Write_count ⇒ Integer (也称为:#n)
获取服务器写入的文档数。
构造函数详情
#initialize (replies, connection_description = nil, connection_global_id = nil, context: nil, connection: nil) ⇒ 结果
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
初始化新结果。
对于未确认的写入,请在回复中传递 nil。
For all other operations, replies must be a Protocol::Message instance or an array containing a single Protocol::Message instance.
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/ Mongo/operation/result.rb', line 107 def 初始化(回复, connection_description = nil, connection_global_id = nil, 上下文: nil, 连接: nil) @context = 上下文 if 回复 if 回复.is_a?(阵列) if 回复.长度 != 1 提高 ArgumentError, " 仅支持一个(或零个)回复,因为 # { replies.length } } " end 回复 = 回复.first else 回复 = 回复 end 除非 回复.is_a?(protocol::message) 提高 ArgumentError, " Argument 必须是 Message 实例,但是是#{ reply . class } : #{ reply .inspect } } " end @replies = [ 回复 ] @connection_description = connection_description @connection_global_id = connection_global_id @connection = 连接 end end |
实例属性详细信息
# 连接 ⇒ 对象(只读)
152 153 154 |
# File 'lib/ Mongo/operation/result.rb', line 152 def 连接 @connection end |
# connection_description ⇒ Server::Description (readonly)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回对该结果执行操作的服务器的MongoDB Server描述。
138 139 140 |
# File 'lib/ Mongo/operation/result.rb', line 138 def connection_description @connection_description end |
# connection_global_id ⇒对象(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回针对此结果所属的操作执行的连接的全局。
144 145 146 |
# File 'lib/ Mongo/operation/result.rb', line 144 def connection_global_id @connection_global_id end |
# context ="Operation::Context | nil(只读)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回生成此结果时处于活动状态的操作上下文(如果有)。
150 151 152 |
# File 'lib/ Mongo/operation/result.rb', line 150 def 上下文 @context end |
#replies ⇒ Array<Protocol::Message> (readonly)
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回回复 包装的传输协议回复。
132 133 134 |
# File 'lib/ Mongo/operation/result.rb', line 132 def 回复 @replies end |
实例方法详细信息
#已确认? ⇒ true , false
在 MongoDB 2.6及更高版本上,所有写入都会得到确认,因为驱动程序对所有写入操作都使用写入命令。 在2.4及更低版本中,如果在命令之后执行了 GLE,则会确认结果。 否则,将不会指定任何回复。 此处读取将始终返回 true,因为始终会提供回复。
是否已确认结果?
170 171 172 |
# File 'lib/ Mongo/operation/result.rb', line 170 def 已确认? !!@replies end |
# cluster_time ⇒ ClusterTime | nil
获取服务器响应中报告的集群时间。
在版本2.9.0中进行了更改: 此属性成为 ClusterTime 的实例,而 ClusterTime 是 BSON::Document 的子类。 以前它是 BSON::Document 的实例。
437 438 439 |
# File 'lib/ Mongo/operation/result.rb', line 437 def cluster_time first_document && ClusterTime[first_document[' $clusterTime ']] end |
# cursor_id = " Integer "
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
游标 ID 为0表示服务器上没有游标。
如果响应得到确认,则获取游标 ID。
194 195 196 |
# File 'lib/ Mongo/operation/result.rb', line 194 def cursor_id 已确认? ? 回复.last.cursor_id : 0 end |
# 个documents ⇒ Array<BSON::Document>
获取结果中的文档。
218 219 220 221 222 223 224 |
# File 'lib/ Mongo/operation/result.rb', line 218 def 文档 if 已确认? 回复.flat_map(和:documents) else [] end end |
#每个{|Each| ... } ⇒枚举器
遍历回复中的文档。
239 240 241 |
# File 'lib/ Mongo/operation/result.rb', line 239 def 每(和块) 文档.每(和块) end |
# error ⇒ Error::OperationFailure::Family
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
处理此结果期间将引发的(Error::OperationFailure::Family 的)异常实例。
仅当结果不成功时才应调用此方法。
354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/ Mongo/operation/result.rb', line 354 def 错误 @error ||= operation_failure_class.new( 解析器., self, 代码: 解析器.代码, code_name: 解析器.code_name, write_concern_error_document: 解析器.write_concern_error_document, write_concern_error_code: 解析器.write_concern_error_code, write_concern_error_code_name: 解析器.write_concern_error_code_name, write_concern_error_labels: 解析器.write_concern_error_labels, 标签: 解析器.labels, wtimeout: 解析器.wtimeout, connection_description: connection_description, 文档: 解析器.文档, server_message: 解析器., ) end |
# has_cursor_id? ⇒ true , false
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
结果是否包含 cursor_id
179 180 181 |
# File 'lib/ Mongo/operation/result.rb', line 179 def has_cursor_id? 已确认? && 回复.last.respond_to?(:cursor_id) end |
#检查⇒ string
获取结果的美观格式检查。
252 253 254 |
# File 'lib/ Mongo/operation/result.rb', line 252 def 检查 " #< #{ self . class . name } : 0 x #{ object_id } documents= #{ documents } > " end |
# labels ⇒数组
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取与结果关联的错误标签集。
450 451 452 |
# File 'lib/ Mongo/operation/result.rb', line 450 def labels @labels ||= 解析器.labels end |
#命名空间⇒ Nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
获取游标的命名空间。 该方法应在结果类中定义,其中“ns”在服务器响应中。
205 206 207 |
# File 'lib/ Mongo/operation/result.rb', line 205 def namespace nil end |
#可以吗? ⇒ true , false
检查第一个文档的 ok 字段。
318 319 320 321 322 323 324 325 |
# File 'lib/ Mongo/operation/result.rb', line 318 def 确定吗? # first_document[OK] 是一个浮点数,服务器可以返回 # 可以作为 BSON int 32 、 BSON int 64或 BSON double 。 # 数字1可以精确地用浮点数表示,因此 # 1.0 == 1将始终正确运行 #(直到服务器返回1以外的其他内容为止) first_document[正常] == 1 end |
# operation_time ⇒对象 | nil
获取服务器响应中报告的 optime。
420 421 422 |
# File 'lib/ Mongo/operation/result.rb', line 420 def operation_time first_document && first_document[OPERATION_TIME] end |
#reply ⇒ Protocol::Message
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
从结果中获取回复。
如果没有回复(即该操作是未确认的写入),则返回 nil。
265 266 267 268 269 270 271 |
# File 'lib/ Mongo/operation/result.rb', line 265 def 回复 if 已确认? 回复.first else nil end end |
# returned_count ⇒整数
获取此批处理中服务器返回的文档数。
279 280 281 282 283 284 285 |
# File 'lib/ Mongo/operation/result.rb', line 279 def returned_count if 已确认? 回复.number_returned else 0 end end |
# snapshot_timestamp ⇒对象
461 462 463 464 465 |
# File 'lib/ Mongo/operation/result.rb', line 461 def if doc = 回复.文档.first doc[' cursor ']&。[ ]('atClusterTime') || doc['atClusterTime'] end end |
#成功? ⇒ true , false
如果写入未被确认,则始终返回 true。
如果结果是命令,则确定是否成功。
300 301 302 303 304 305 306 307 |
# File 'lib/ Mongo/operation/result.rb', line 300 def 成功? return true if !已确认? if first_document.has_key?(正常) 确定吗? && 解析器..空? else !query_failure? && 解析器..空? end end |
# topology_version ⇒ TopologyVersion | nil
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
返回 拓扑版本。
383 384 385 386 387 388 389 |
# File 'lib/ Mongo/operation/result.rb', line 383 def topology_version 除非 定义?(@topology_version) @topology_version = first_document['topologyVersion'] && TopologyVersion.new(first_document['topologyVersion']) end @topology_version end |
# validate! ⇒结果
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
这只检查写入错误,因为身份验证是在连接级别处理的,并且在创建结果之前,任何身份验证错误都会在那里引发。
通过检查是否存在任何错误来验证结果。
342 343 344 |
# File 'lib/ Mongo/operation/result.rb', line 342 def validate! !成功? ? Raise_operation_failure : self end |
# write_concern_error? ⇒布尔
此方法是私有 API 的一部分。 您应尽可能避免使用此方法,因为它将来可能会被删除或更改。
操作是否因写关注错误而失败。
457 458 459 |
# File 'lib/ Mongo/operation/result.rb', line 457 def write_concern_error? !!(first_document && first_document[' writeConcernError ']) end |
# Write_count ⇒ Integer也称为: n
获取服务器写入的文档数。
400 401 402 403 404 405 406 |
# File 'lib/ Mongo/operation/result.rb', line 400 def Write_Count if 已确认? first_document[N] || 0 else 0 end end |