lib/mongo_doc/contexts/mongo.rb in mongo_doc-0.6.6 vs lib/mongo_doc/contexts/mongo.rb in mongo_doc-0.6.7

- old
+ new

@@ -53,11 +53,11 @@ # # Returns: # # An +Integer+ count of documents. def count - @count ||= collection.find(selector, options).count + @count ||= collection.find(selector, find_options).count end # Gets an array of distinct values for the supplied field across the # entire collection or the susbset given the criteria. # @@ -73,11 +73,11 @@ # # Example: # # <tt>context.blank?</tt> def empty? - collection.find_one(selector, options).nil? + collection.find_one(selector, find_options).nil? end alias blank? empty? # Execute the context. This will take the selector and options # and pass them on to the Ruby driver's +find()+ method on the collection. The @@ -90,11 +90,11 @@ # # Returns: # # An enumerable +Cursor+. def execute(paginating = false) - cursor = collection.find(selector, options) + cursor = collection.find(selector, find_options) if cursor @count = cursor.count if paginating cursor else [] @@ -161,11 +161,11 @@ # # The last document in the collection. def last sorting = options[:sort] || [[:_id, :asc]] options[:sort] = sorting.collect { |option| [ option[0], option[1].invert ] } - collection.find_one(selector, options) + collection.find_one(selector, find_options) end MAX_REDUCE = "function(obj, prev) { if (prev.max == 'start') { prev.max = obj.[field]; } " + "if (prev.max < obj.[field]) { prev.max = obj.[field]; } }" # Return the max value for a field. @@ -214,11 +214,11 @@ # # Return: # # The first document in the collection. def one - collection.find_one(selector, options) + collection.find_one(selector, find_options) end alias first one SUM_REDUCE = "function(obj, prev) { if (prev.sum == 'start') { prev.sum = 0; } prev.sum += obj.[field]; }" @@ -264,9 +264,13 @@ execute.each do |doc| @cache << doc yield doc if block_given? end end + end + + def find_options + options.except(:cache, :enslave) end end end end