Class: Mongo::Operation::Insert::Result

Inherits:
Result
  • Object
show all
Defined in:
build/ruby-driver-v2.19/lib/mongo/operation/insert/result.rb

Overview

Defines custom behavior of results for an insert.

According to the CRUD spec, reporting the inserted ids is optional. It can be added to this class later, if needed.

Since:

  • 2.0.0

Constant Summary

Constants inherited from Result

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

Instance Attribute Summary collapse

Attributes inherited from Result

#connection_description, #connection_global_id, #replies

Instance Method Summary collapse

Methods inherited from 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?, #written_count

Constructor Details

#initialize(replies, connection_description, connection_global_id, ids) ⇒ Result

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize a new result.

Examples:

Instantiate the result.

Result.new(replies, inserted_ids)

Parameters:

  • replies (Array<Protocol::Message> | nil)

    The wire protocol replies, if any.

  • connection_description (Server::Description)

    Server description of the server that performed the operation that this result is for.

  • connection_global_id (Integer)

    Global id of the connection on which the operation that this result is for was performed.

  • ids (Array<Object>)

    The ids of the inserted documents.

Since:

  • 2.0.0



53
54
55
56
# File 'build/ruby-driver-v2.19/lib/mongo/operation/insert/result.rb', line 53

def initialize(replies, connection_description, connection_global_id, ids)
  super(replies, connection_description, connection_global_id)
  @inserted_ids = ids
end

Instance Attribute Details

#inserted_idsObject (readonly)

Get the ids of the inserted documents.

Since:

  • 2.0.0



35
36
37
# File 'build/ruby-driver-v2.19/lib/mongo/operation/insert/result.rb', line 35

def inserted_ids
  @inserted_ids
end

Instance Method Details

#bulk_resultObject

Since:

  • 2.0.0



72
73
74
# File 'build/ruby-driver-v2.19/lib/mongo/operation/insert/result.rb', line 72

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

#inserted_idObject

Gets the id of the document inserted.

Examples:

Get id of the document inserted.

result.inserted_id

Returns:

  • (Object)

    The id of the document inserted.

Since:

  • 2.0.0



67
68
69
# File 'build/ruby-driver-v2.19/lib/mongo/operation/insert/result.rb', line 67

def inserted_id
  inserted_ids.first
end