Class: Mongo::Protocol::Query::Upconverter
- Inherits:
-
Object
- Object
- Mongo::Protocol::Query::Upconverter
- Defined in:
- lib/mongo/protocol/query.rb
Overview
Converts legacy query messages to the appropriate OP_COMMAND style message.
Constant Summary collapse
- OPTION_MAPPINGS =
Mappings of the options to the find command options.
{ project: 'projection', skip: 'skip', limit: 'limit', batch_size: 'batchSize' }.freeze
- SPECIAL_FIELD_MAPPINGS =
{ :$readPreference => '$readPreference', :$orderby => 'sort', :$hint => 'hint', :$comment => 'comment', :$returnKey => 'returnKey', :$snapshot => 'snapshot', :$maxScan => 'maxScan', :$max => 'max', :$min => 'min', :$maxTimeMS => 'maxTimeMS', :$showDiskLoc => 'showRecordId', :$explain => 'explain' }.freeze
- FLAG_MAPPINGS =
Mapping of flags to find command options.
{ tailable_cursor: 'tailable', oplog_replay: 'oplogReplay', no_cursor_timeout: 'noCursorTimeout', await_data: 'awaitData', partial: 'allowPartialResults' }.freeze
Instance Attribute Summary collapse
-
#collection ⇒ String
readonly
Collection The name of the collection.
-
#filter ⇒ BSON::Document, Hash
readonly
Filter The query filter or command.
-
#flags ⇒ Array<Symbol>
readonly
Flags The flags.
-
#options ⇒ BSON::Document, Hash
readonly
Options The options.
Instance Method Summary collapse
-
#command ⇒ BSON::Document
Get the upconverted command.
-
#command_name ⇒ String
Get the name of the command.
-
#initialize(collection, filter, options, flags) ⇒ Upconverter
constructor
Instantiate the upconverter.
Constructor Details
#initialize(collection, filter, options, flags) ⇒ Upconverter
Instantiate the upconverter.
279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/mongo/protocol/query.rb', line 279 def initialize(collection, filter, , flags) # Although the docstring claims both hashes and BSON::Documents # are acceptable, this class expects the filter and options to # contain symbol keys which isn't what the operation layer produces. raise ArgumentError, 'Filter must provide indifferent access' unless filter.is_a?(BSON::Document) raise ArgumentError, 'Options must provide indifferent access' unless .is_a?(BSON::Document) @collection = collection @filter = filter @options = @flags = flags end |
Instance Attribute Details
#collection ⇒ String (readonly)
Returns collection The name of the collection.
257 258 259 |
# File 'lib/mongo/protocol/query.rb', line 257 def collection @collection end |
#filter ⇒ BSON::Document, Hash (readonly)
Returns filter The query filter or command.
260 261 262 |
# File 'lib/mongo/protocol/query.rb', line 260 def filter @filter end |
#flags ⇒ Array<Symbol> (readonly)
Returns flags The flags.
266 267 268 |
# File 'lib/mongo/protocol/query.rb', line 266 def flags @flags end |
#options ⇒ BSON::Document, Hash (readonly)
Returns options The options.
263 264 265 |
# File 'lib/mongo/protocol/query.rb', line 263 def @options end |
Instance Method Details
#command ⇒ BSON::Document
Get the upconverted command.
300 301 302 |
# File 'lib/mongo/protocol/query.rb', line 300 def command command? ? op_command : find_command end |
#command_name ⇒ String
Get the name of the command. If the collection is $cmd then it’s the first key in the filter, otherwise it’s a find.
313 314 315 |
# File 'lib/mongo/protocol/query.rb', line 313 def command_name ((filter[:$query] || !command?) ? :find : filter.keys.first).to_s end |