Class: Mongo::Operation::MapReduce::Result

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

Overview

Defines custom behavior of results for a map reduce operation.

Since:

  • 2.0.0

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.

Since:

  • 2.0.0

'counts'.freeze
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.

Since:

  • 2.0.0

'results'.freeze
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.

Since:

  • 2.0.0

'timeMillis'.freeze

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_description, #connection_global_id, #replies

Instance Method Summary collapse

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

#countsHash

Gets the map/reduce counts from the reply.

Examples:

Get the counts.

result.counts

Returns:

  • (Hash)

    A hash of the result counts.

Since:

  • 2.0.0



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

def counts
  reply.documents[0][COUNTS]
end

#cursor_idInteger

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.

Examples:

Get the cursor id.

result.cursor_id

Returns:

  • (Integer)

    Always 0 because map reduce doesn’t return a cursor.

Since:

  • 2.5.0



130
131
132
# File 'build/ruby-driver-v2.19/lib/mongo/operation/map_reduce/result.rb', line 130

def cursor_id
  0
end

#documentsArray<BSON::Document>

Get the documents from the map/reduce.

Examples:

Get the documents.

result.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



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

def documents
  reply.documents[0][RESULTS] || reply.documents[0][RESULT]
end

#returned_countInteger

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.

Returns:

  • (Integer)

    The number of documents returned.

Since:

  • 2.0.0



146
147
148
# File 'build/ruby-driver-v2.19/lib/mongo/operation/map_reduce/result.rb', line 146

def returned_count
  reply.documents.length
end

#successful?true, false

Note:

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.

Examples:

Was the command successful?

result.successful?

Returns:

  • (true, false)

    If the command was successful.

Since:

  • 2.0.0



85
86
87
# File 'build/ruby-driver-v2.19/lib/mongo/operation/map_reduce/result.rb', line 85

def successful?
  !documents.nil?
end

#timeInteger

Get the execution time of the map/reduce.

Examples:

Get the execution time.

result.time

Returns:

  • (Integer)

    The executing time in milliseconds.

Since:

  • 2.0.0



98
99
100
# File 'build/ruby-driver-v2.19/lib/mongo/operation/map_reduce/result.rb', line 98

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.

Note:

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.

Examples:

Validate the result.

result.validate!

Returns:

  • (Result)

    The result if verification passed.

Raises:

Since:

  • 2.0.0



117
118
119
# File 'build/ruby-driver-v2.19/lib/mongo/operation/map_reduce/result.rb', line 117

def validate!
  documents.nil? ? raise_operation_failure : self
end