Class: Mongo::Operation::MapReduce::Result
- Defined in:
- lib/mongo/operation/map_reduce/result.rb
Overview
Defines custom behavior of results for a map reduce operation.
Constant Summary collapse
- COUNTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The counts field for the map/reduce.
'counts'- RESULTS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The field name for a result without a cursor.
'results'- TIME =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The time the operation took constant.
'timeMillis'
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
Attributes inherited from Result
#connection, #connection_description, #connection_global_id, #context, #replies
Instance Method Summary collapse
-
#counts ⇒ Hash
Gets the map/reduce counts from the reply.
-
#cursor_id ⇒ Integer
private
Get the cursor id.
-
#documents ⇒ Array<BSON::Document>
Get the documents from the map/reduce.
-
#returned_count ⇒ Integer
Get the number of documents returned by the server in this batch.
-
#successful? ⇒ true, false
If the result was a command then determine if it was considered a success.
-
#time ⇒ Integer
Get the execution time of the map/reduce.
-
#validate! ⇒ Result
private
Validate the result by checking for any errors.
Methods inherited from Result
#acknowledged?, #cluster_time, #each, #error, #has_cursor_id?, #initialize, #inspect, #labels, #namespace, #ok?, #operation_time, #reply, #snapshot_timestamp, #topology_version, #write_concern_error?, #written_count
Constructor Details
This class inherits a constructor from Mongo::Operation::Result
Instance Method Details
#counts ⇒ Hash
Gets the map/reduce counts from the reply.
52 53 54 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 52 def counts reply.documents[0][COUNTS] end |
#cursor_id ⇒ Integer
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.
Get the cursor id.
127 128 129 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 127 def cursor_id 0 end |
#documents ⇒ Array<BSON::Document>
Get the documents from the map/reduce.
65 66 67 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 65 def documents reply.documents[0][RESULTS] || reply.documents[0][RESULT] end |
#returned_count ⇒ Integer
Get the number of documents returned by the server in this batch.
Map/Reduce operation returns documents inline without using cursors; as such, the standard Mongo::Reply#returned_count does not work correctly for Map/Reduce.
Note that the Map/Reduce operation is limited to max BSON document size (16 MB) in its inline result set.
143 144 145 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 143 def returned_count reply.documents.length end |
#successful? ⇒ true, false
If the write was unacknowledged, then this will always return true.
If the result was a command then determine if it was considered a success.
82 83 84 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 82 def successful? !documents.nil? end |
#time ⇒ Integer
Get the execution time of the map/reduce.
95 96 97 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 95 def time reply.documents[0][TIME] end |
#validate! ⇒ 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.
This only checks for errors with writes since authentication is handled at the connection level and any authentication errors would be raised there, before a Result is ever created.
Validate the result by checking for any errors.
114 115 116 |
# File 'lib/mongo/operation/map_reduce/result.rb', line 114 def validate! documents.nil? ? raise_operation_failure : self end |