Class: Mongo::Protocol::Query::Upconverter
- Inherits:
-
Object
- Object
- Mongo::Protocol::Query::Upconverter
- Defined in:
- build/ruby-driver-v2.19/lib/mongo/protocol/query.rb
Overview
Converts legacy query messages to the appropriare 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.
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 283 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. unless BSON::Document === filter raise ArgumentError, 'Filter must provide indifferent access' end unless BSON::Document === raise ArgumentError, 'Options must provide indifferent access' end @collection = collection @filter = filter @options = @flags = flags end |
Instance Attribute Details
#collection ⇒ String (readonly)
Returns collection The name of the collection.
261 262 263 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 261 def collection @collection end |
#filter ⇒ BSON::Document, Hash (readonly)
Returns filter The query filter or command.
264 265 266 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 264 def filter @filter end |
#flags ⇒ Array<Symbol> (readonly)
Returns flags The flags.
270 271 272 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 270 def flags @flags end |
#options ⇒ BSON::Document, Hash (readonly)
Returns options The options.
267 268 269 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 267 def @options end |
Instance Method Details
#command ⇒ BSON::Document
Get the upconverted command.
307 308 309 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 307 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.
320 321 322 |
# File 'build/ruby-driver-v2.19/lib/mongo/protocol/query.rb', line 320 def command_name ((filter[:$query] || !command?) ? :find : filter.keys.first).to_s end |