Class: Mongo::Protocol::Query
- Includes:
- Monitoring::Event::Secure
- Defined in:
- lib/mongo/protocol/query.rb
Overview
MongoDB Wire protocol Query message.
This is a client request message that is sent to the server in order to retrieve documents matching provided query.
Users may also provide additional options such as a projection, to select a subset of the fields, a number to skip or a limit on the number of returned documents.
There are a variety of flags that can be used to adjust cursor parameters or the desired consistency and integrity the results.
Defined Under Namespace
Classes: Upconverter
Constant Summary
Constants included from Monitoring::Event::Secure
Monitoring::Event::Secure::REDACTED_COMMANDS
Constants inherited from Message
Message::BATCH_SIZE, Message::COLLECTION, Message::LIMIT, Message::MAX_MESSAGE_SIZE, Message::ORDERED, Message::Q
Constants included from Serializers
Serializers::HEADER_PACK, Serializers::INT32_PACK, Serializers::INT64_PACK, Serializers::NULL, Serializers::ZERO
Instance Attribute Summary
Attributes inherited from Message
Instance Method Summary collapse
-
#initialize(database, collection, selector, options = {}) ⇒ Query
constructor
Creates a new Query message.
-
#maybe_compress(compressor, zlib_compression_level = nil) ⇒ Message
private
Compress the message, if the command being sent permits compression.
-
#payload ⇒ BSON::Document
Return the event payload for monitoring.
-
#replyable? ⇒ true
Query messages require replies from the database.
-
#serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil) ⇒ BSON::ByteBuffer
Serializes message into bytes that can be sent on the wire.
Methods included from Monitoring::Event::Secure
#compression_allowed?, #redacted, #sensitive?
Methods inherited from Message
#==, deserialize, deserialize_array, deserialize_field, deserialize_header, field, fields, #hash, #maybe_add_server_api, #maybe_decrypt, #maybe_encrypt, #maybe_inflate, #number_returned, #set_request_id
Methods included from Id
Constructor Details
#initialize(database, collection, selector, options = {}) ⇒ Query
Creates a new Query message
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/mongo/protocol/query.rb', line 62 def initialize(database, collection, selector, = {}) @database = database @namespace = "#{database}.#{collection}" raise ArgumentError, 'Selector cannot be nil' if selector.nil? @selector = selector @options = @project = [:project] @limit = determine_limit @skip = [:skip] || 0 @flags = [:flags] || [] @upconverter = Upconverter.new( collection, BSON::Document.new(selector), BSON::Document.new(), flags ) super end |
Instance Method Details
#maybe_compress(compressor, zlib_compression_level = nil) ⇒ Message
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.
Compress the message, if the command being sent permits compression. Otherwise returns self.
122 123 124 |
# File 'lib/mongo/protocol/query.rb', line 122 def maybe_compress(compressor, zlib_compression_level = nil) compress_if_possible(selector.keys.first, compressor, zlib_compression_level) end |
#payload ⇒ BSON::Document
Return the event payload for monitoring.
90 91 92 93 94 95 96 97 |
# File 'lib/mongo/protocol/query.rb', line 90 def payload BSON::Document.new( command_name: upconverter.command_name, database_name: @database, command: upconverter.command, request_id: request_id ) end |
#replyable? ⇒ true
Query messages require replies from the database.
107 108 109 |
# File 'lib/mongo/protocol/query.rb', line 107 def replyable? true end |
#serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil) ⇒ BSON::ByteBuffer
Serializes message into bytes that can be sent on the wire.
132 133 134 135 136 |
# File 'lib/mongo/protocol/query.rb', line 132 def serialize(buffer = BSON::ByteBuffer.new, max_bson_size = nil, bson_overhead = nil) validate_document_size!(max_bson_size) super end |