Class | Moped::Protocol::Query |
In: |
lib/moped/protocol/query.rb
|
Parent: | Object |
The Protocol class for querying a collection.
@since 1.0.0
batch_size | [RW] |
@!attribute batch_size
@return [ Integer ] The batch size of the results. |
collection | [R] |
@!attribute collection
@return [ String ] The collection to query. @!attribute database @return [ String ] The database to query |
database | [R] |
@!attribute collection
@return [ String ] The collection to query. @!attribute database @return [ String ] The database to query |
Instantiate a new query operation.
@example Find all users named John.
Query.new("moped", "users", { name: "John" })
@example Find all users named John skipping 5 and returning 10.
Query.new("moped", "users", { name: "John" }, skip: 5, limit: 10)
@example Find all users on slave node.
Query.new("moped", "users", {}, flags: [ :slave_ok ])
@example Find all user ids.
Query.new("moped", "users", {}, fields: { _id: 1 })
@param [ String, Symbol ] database The database to query. @param [ String, Symbol ] collection The collection to query. @param [ Hash ] selector The query selector. @param [ Hash ] options The additional query options.
@option options [ Integer ] :request_id The operation‘s request id. @option options [ Integer ] :skip The number of documents to skip. @option options [ Integer ] :limit The number of documents to return. @option options [ Hash ] :fields The limited fields to return. @option options [ Array ] :flags The flags for querying. Supported flags
are: :tailable, :slave_ok, :no_cursor_timeout, :await_data, :exhaust.
@since 1.0.0
Get the basic selector.
@example Get the basic selector.
query.basic_selector
@note Sometimes, like in cases of deletion we need this since MongoDB
does not understand $query in operations like DELETE.
@return [ Hash ] The basic selector.
@since 2.0.0
Get the exception specific to a failure of this particular operation.
@example Get the failure exception.
query.failure_exception(document)
@param [ Moped::Protocol::Reply ] reply The reply from the database.
@return [ Moped::Errors::QueryFailure ] The failure exception.
@since 2.0.0
Provide the value that will be logged when the query runs.
@example Provide the log inspection.
query.log_inspect
@return [ String ] The string value for logging.
@since 1.0.0
Set the option on the query to not timeout the cursor.
@example Set the no timeout option.
query.no_timeout = true
@param [ true, false ] enable Whether to enable the no timeout option.
@since 1.3.0
Get the code for a query operation.
@example Get the operation code.
query.op_code
@return [ Integer ] OP_QUERY operation code (2004).
@since 1.0.0
Receive replies to the message.
@example Receive replies.
message.receive_replies(connection)
@param [ Connection ] connection The connection.
@return [ Protocol::Reply ] The reply.
@since 1.0.0
Take the provided reply and return the expected results to api consumers.
@example Get the expected results of the reply.
query.results(reply)
@param [ Moped::Protocol::Reply ] reply The reply from the database.
@return [ Moped::Protocol::Reply ] The reply.
@since 2.0.0