Method: Moped::Protocol::Query#initialize

Defined in:
lib/moped/protocol/query.rb

#initialize(database, collection, selector, options = {}) ⇒ Query

Instantiate a new query operation.

Examples:

Find all users named John.

Query.new("moped", "users", { name: "John" })

Find all users named John skipping 5 and returning 10.

Query.new("moped", "users", { name: "John" }, skip: 5, limit: 10)

Find all users on slave node.

Query.new("moped", "users", {}, flags: [ :slave_ok ])

Find all user ids.

Query.new("moped", "users", {}, fields: { _id: 1 })

Parameters:

  • database (String, Symbol)

    The database to query.

  • collection (String, Symbol)

    The collection to query.

  • selector (Hash)

    The query selector.

  • options (Hash) (defaults to: {})

    The additional query options.

Options Hash (options):

  • :request_id (Integer)

    The operation’s request id.

  • :skip (Integer)

    The number of documents to skip.

  • :limit (Integer)

    The number of documents to return.

  • :fields (Hash)

    The limited fields to return.

  • :flags (Array)

    The flags for querying. Supported flags are: :tailable, :slave_ok, :no_cursor_timeout, :await_data, :exhaust.

Since:

  • 1.0.0



151
152
153
154
155
156
157
158
159
160
161
162
# File 'lib/moped/protocol/query.rb', line 151

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