Parent

Included Modules

Class/Module Index [+]

Quicksearch

Moped::Protocol::Query

The Protocol class for querying a collection.

@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 }

Attributes

batch_size[RW]
collection[R]

@return [String, Symbol] the collection to query

database[R]

@return [String, Symbol] the database to query

Public Class Methods

new(database, collection, selector, options = {}) click to toggle source

Create a new query command.

@example

Query.new "moped", "users", { name: "John" },
  skip: 5,
  limit: 10,
  request_id: 12930,
  fields: { _id: -1, name: 1 }

@param [String, Symbol] database the database to insert into @param [String, Symbol] collection the collection to insert into @param [Hash] selector the query @param [Hash] options additional options @option options [Number] :request_id the command's request id @option options [Number] :skip the number of documents to skip @option options [Number] :limit the number of documents to return @option options [Hash] :fields the fields to return @option options [Array] :flags the flags for querying. Supported

flags: +:tailable+, +:slave_ok+, +:no_cursor_timeout+, +:await_data+,
+:exhaust+.
# File lib/moped/protocol/query.rb, line 107
def initialize(database, collection, selector, options = {})
  @database = database
  @collection = collection

  @full_collection_name = "#{database}.#{collection}"
  @selector             = selector
  @request_id           = options[:request_id]
  @flags                = options[:flags] || []
  @limit                = options[:limit]
  @skip                 = options[:skip]
  @fields               = options[:fields]
  @batch_size           = options[:batch_size]
end

Public Instance Methods

basic_selector() click to toggle source

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

# File lib/moped/protocol/query.rb, line 148
def basic_selector
  selector["$query"] || selector
end
log_inspect() click to toggle source
# File lib/moped/protocol/query.rb, line 121
def log_inspect
  type = "QUERY"
  fields = []
  fields << ["%-12s", type]
  fields << ["database=%s", database]
  fields << ["collection=%s", collection]
  fields << ["selector=%s", selector.inspect]
  fields << ["flags=%s", flags.inspect]
  fields << ["limit=%s", limit.inspect]
  fields << ["skip=%s", skip.inspect]
  fields << ["batch_size=%s", batch_size.inspect]
  fields << ["fields=%s", self.fields.inspect]
  f, v = fields.transpose
  f.join(" ") % v
end
no_timeout=(enable) click to toggle source
# File lib/moped/protocol/query.rb, line 83
def no_timeout=(enable)
  @flags |= [:no_cursor_timeout] if enable
end
op_code() click to toggle source

@return [Number] OP_QUERY operation code (2004)

# File lib/moped/protocol/query.rb, line 71
def op_code
  2004
end
receive_replies(connection) click to toggle source

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

# File lib/moped/protocol/query.rb, line 162
def receive_replies(connection)
  connection.read
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.