Class: Mongo::Operation::ListCollections::Result

Inherits:
Result
  • Object
show all
Defined in:
lib/mongo/operation/list_collections/result.rb

Overview

Defines custom behavior of results when using the listCollections command.

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

Attributes inherited from Result

#connection, #connection_description, #connection_global_id, #context, #replies

Instance Method Summary collapse

Methods inherited from Result

#acknowledged?, #cluster_time, #each, #error, #has_cursor_id?, #initialize, #inspect, #labels, #ok?, #operation_time, #reply, #returned_count, #snapshot_timestamp, #successful?, #topology_version, #write_concern_error?, #written_count

Constructor Details

This class inherits a constructor from Mongo::Operation::Result

Instance Method Details

#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.

Note:

Even though the wire protocol has a cursor_id field for all messages of type reply, it is always zero when using the listCollections command and must be retrieved from the cursor document itself.

Get the cursor id for the result.

Examples:

Get the cursor id.

result.cursor_id

Returns:

  • (Integer)

    The cursor id.

Since:

  • 2.0.0



43
44
45
# File 'lib/mongo/operation/list_collections/result.rb', line 43

def cursor_id
  cursor_document ? cursor_document[CURSOR_ID] : super
end

#documentsArray<BSON::Document>

Get the documents for the listCollections result. It is the ‘firstBatch’

field in the 'cursor' field of the first document returned.

Examples:

Get the documents.

result.documents

Returns:

  • (Array<BSON::Document>)

    The documents.

Since:

  • 2.0.0



70
71
72
# File 'lib/mongo/operation/list_collections/result.rb', line 70

def documents
  cursor_document[FIRST_BATCH]
end

#namespaceString

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 namespace for the cursor.

Examples:

Get the namespace.

result.namespace

Returns:

  • (String)

    The namespace.

Since:

  • 2.0.0



56
57
58
# File 'lib/mongo/operation/list_collections/result.rb', line 56

def namespace
  cursor_document ? cursor_document[NAMESPACE] : super
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.

Validate the result. In the case where an unauthorized client tries to run the command we need to generate the proper error.

Examples:

Validate the result.

result.validate!

Returns:

  • (Result)

    Self if successful.

Since:

  • 2.0.0



84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/mongo/operation/list_collections/result.rb', line 84

def validate!
  if successful?
    self
  else
    raise operation_failure_class.new(
      parser.message,
      self,
      code: parser.code,
      code_name: parser.code_name,
      labels: parser.labels,
      wtimeout: parser.wtimeout,
      document: parser.document,
      server_message: parser.server_message,
    )
  end
end