diff --git a/lib/mongo/admin.rb b/lib/mongo/admin.rb index 1ce950a..6838969 100644 --- a/lib/mongo/admin.rb +++ b/lib/mongo/admin.rb @@ -66,7 +66,7 @@ module XGen # Return an array contining current profiling information from the # database. def profiling_info - @db.query(DB::SYSTEM_PROFILE_COLLECTION, Query.new({})).to_a + @db.query(Collection.new(@db, DB::SYSTEM_PROFILE_COLLECTION), Query.new({})).to_a end # Validate a named collection by raising an exception if there is a diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index 171c8a3..ab2b377 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -25,6 +25,9 @@ module XGen attr_reader :db, :name + # A single field name or array of field names. May be +nil+. + attr_accessor :hint_fields + def initialize(db, name) @db = db @name = name @@ -47,7 +50,7 @@ module XGen limit = options.delete(:limit) || 0 sort = options.delete(:sort) raise RuntimeError, "Unknown options [#{options.inspect}]" unless options.empty? - @db.query(@name, Query.new(selector, fields, offset, limit, sort)) + @db.query(self, Query.new(selector, fields, offset, limit, sort)) end # Insert +objects+, which are hashes. "<<" is aliased to this method. diff --git a/lib/mongo/cursor.rb b/lib/mongo/cursor.rb index fbe6a95..eebf4ea 100644 --- a/lib/mongo/cursor.rb +++ b/lib/mongo/cursor.rb @@ -31,6 +31,9 @@ module XGen attr_reader :db, :collection, :query_message + # A single field name or array of field names. May be +nil+. + attr_accessor :hint_fields + def initialize(db, collection, query_message) @db, @collection, @query_message = db, collection, query_message @num_to_return = query_message.query.number_to_return || 0 @@ -110,7 +113,7 @@ module XGen sel = OrderedHash.new sel['query'] = @query_message.query.selector sel['$explain'] = true - c = Cursor.new(@db, @collection, QueryMessage.new(@db.name, @collection, Query.new(sel))) + c = Cursor.new(@db, @collection, QueryMessage.new(@db.name, @collection.name, Query.new(sel))) e = c.next_object c.close e @@ -173,7 +176,7 @@ module XGen def refill_via_get_more send_query_if_needed return if @cursor_id == 0 - @db.send_to_db(GetMoreMessage.new(@db.name, @collection, @cursor_id)) + @db.send_to_db(GetMoreMessage.new(@db.name, @collection.name, @cursor_id)) read_all end diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 673a011..ce5b912 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -84,7 +84,7 @@ module XGen def collections_info(coll_name=nil) selector = {} selector[:name] = full_coll_name(coll_name) if coll_name - query(SYSTEM_NAMESPACE_COLLECTION, Query.new(selector)) + query(Collection.new(self, SYSTEM_NAMESPACE_COLLECTION), Query.new(selector)) end # Create a collection. If +strict+ is false, will return existing or @@ -182,8 +182,8 @@ module XGen # Note that the query gets sent lazily; the cursor calls # #send_query_message when needed. If the caller never requests an # object from the cursor, the query never gets sent. - def query(collection_name, query) - Cursor.new(self, collection_name, QueryMessage.new(@name, collection_name, query)) + def query(collection, query) + Cursor.new(self, collection, QueryMessage.new(@name, collection.name, query)) end # Used by a Cursor to lazily send the query to the database. @@ -256,7 +256,7 @@ module XGen # :ns :: Namespace; same as +collection_name+. def index_information(collection_name) sel = {:ns => full_coll_name(collection_name)} - query(SYSTEM_INDEX_COLLECTION, Query.new(sel)).collect { |row| + query(Collection.new(self, SYSTEM_INDEX_COLLECTION), Query.new(sel)).collect { |row| h = {:name => row['name']} raise "Name of index on return from db was nil. Coll = #{full_coll_name(collection_name)}" unless h[:name] @@ -321,7 +321,7 @@ module XGen q = Query.new(selector) q.number_to_return = 1 - query(SYSTEM_COMMAND_COLLECTION, q).next_object + query(Collection.new(self, SYSTEM_COMMAND_COLLECTION), q).next_object end end