Method: Mongo::Protocol::Query#initialize

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

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

Creates a new Query message

Examples:

Find all users named Tyler.

Query.new('xgen', 'users', {:name => 'Tyler'})

Find all users named Tyler skipping 5 and returning 10.

Query.new('xgen', 'users', {:name => 'Tyler'}, :skip => 5,
                                               :limit => 10)

Find all users with slave ok bit set

Query.new('xgen', 'users', {:name => 'Tyler'}, :flags => [:slave_ok])

Find all user ids.

Query.new('xgen', '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):

  • :project (Hash)

    The projection.

  • :skip (Integer)

    The number of documents to skip.

  • :limit (Integer)

    The number of documents to return.

  • :flags (Array)

    The flags for the query message.

    Supported flags: :tailable_cursor, :slave_ok, :oplog_replay, :no_cursor_timeout, :await_data, :exhaust, :partial



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/mongo/protocol/query.rb', line 61

def initialize(database, collection, selector, options = {})
  @database = database
  @namespace = "#{database}.#{collection}"
  @selector = selector
  @options = options
  @project = options[:project]
  @limit = determine_limit
  @skip = options[:skip]  || 0
  @flags = options[:flags] || []
  @upconverter = Upconverter.new(collection, selector, options, flags)
  super
end