123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Database::CursorCommandView Private

Relationships & Source Files
Inherits: Object
Defined in: lib/mongo/database/cursor_command_view.rb

Overview

The minimal view a ::Mongo::Cursor needs when it is built from an arbitrary command response rather than from a collection query.

It carries the getMore-specific options (batchSize, maxTimeMS, comment) and the cursor type and timeout mode, and answers the few methods the ::Mongo::Cursor reads from its view.

Since:

  • 2.0.0

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(database, options = {}) ⇒ CursorCommandView

Parameters:

  • database (Mongo::Database)

    The database the command ran on.

  • options (Hash) (defaults to: {})

    The getMore and timeout options.

Options Hash (options):

  • :batch_size (Integer)

    The batchSize for getMores.

  • :max_time_ms (Integer)

    The maxTimeMS for getMores.

  • :comment (Object)

    The comment for getMores.

  • :cursor_type (Symbol)

    :tailable or :tailable_await.

  • :timeout_mode (Symbol)

    :cursor_lifetime or :iteration.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 36

def initialize(database, options = {})
  @database = database
  @options = options
end

Instance Attribute Details

#databaseMongo::Database (readonly)

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 42

attr_reader :database

#optionsHash (readonly)

Returns:

  • (Hash)

    The view options. Used by the ::Mongo::Cursor to read the getMore comment.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 46

attr_reader :options

Instance Method Details

#batch_sizeInteger | nil

Returns:

  • (Integer | nil)

    The batchSize sent on getMore commands.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 63

def batch_size
  options[:batch_size]
end

#clientMongo::Client

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 49

def client
  database.client
end

#collectionMongo::Collection

A placeholder collection used only so the ::Mongo::Cursor can reach the client and database. The actual namespace for getMore and killCursors is taken from the command response, not from this collection.

Returns:

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 58

def collection
  @collection ||= Collection.new(database, '$cmd')
end

#cursor_typeSymbol | nil

Returns:

  • (Symbol | nil)

    The cursor type.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 73

def cursor_type
  options[:cursor_type]
end

#limit (private)

Cursors do not support a limit when built from a command response.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 90

def limit
  nil
end

#max_time_ms_for_get_moreInteger | nil

Returns:

  • (Integer | nil)

    The maxTimeMS sent on getMore commands.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 68

def max_time_ms_for_get_more
  options[:max_time_ms]
end

#operation_timeouts(opts = {}) ⇒ Hash

Returns:

  • (Hash)

    timeout values for the operation context.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 83

def operation_timeouts(opts = {})
  database.operation_timeouts(opts)
end

#timeout_modeSymbol | nil

Returns:

  • (Symbol | nil)

    The timeout mode.

Since:

  • 2.0.0

[ GitHub ]

  
# File 'lib/mongo/database/cursor_command_view.rb', line 78

def timeout_mode
  options[:timeout_mode]
end