Class: Mongo::Operation::Write::Insert::Result
- Defined in:
- lib/mongo/operation/write/insert/result.rb
Overview
Defines custom behaviour 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.
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
-
#inserted_ids ⇒ Object
readonly
Get the ids of the inserted documents.
Attributes inherited from Result
Instance Method Summary collapse
-
#initialize(replies, ids) ⇒ Result
constructor
Initialize a new result.
-
#inserted_id ⇒ Object
Gets the id of the document inserted.
Methods inherited from Result
#acknowledged?, #cursor_id, #documents, #each, #inspect, #multiple?, #namespace, #ok?, #reply, #returned_count, #successful?, #validate!, #written_count
Constructor Details
#initialize(replies, ids) ⇒ Result
Initialize a new result.
42 43 44 45 |
# File 'lib/mongo/operation/write/insert/result.rb', line 42 def initialize(replies, ids) @replies = replies.is_a?(Protocol::Reply) ? [ replies ] : replies @inserted_ids = ids end |
Instance Attribute Details
#inserted_ids ⇒ Object (readonly)
Get the ids of the inserted documents.
31 32 33 |
# File 'lib/mongo/operation/write/insert/result.rb', line 31 def inserted_ids @inserted_ids end |
Instance Method Details
#inserted_id ⇒ Object
Gets the id of the document inserted.
55 56 57 |
# File 'lib/mongo/operation/write/insert/result.rb', line 55 def inserted_id inserted_ids.first end |