lib/mongo/collection/view/aggregation.rb in mongo-2.13.3 vs lib/mongo/collection/view/aggregation.rb in mongo-2.14.0.rc1

- old
+ new

@@ -87,10 +87,20 @@ # @since 2.0.0 def explain self.class.new(view, pipeline, options.merge(explain: true)).first end + # Whether this aggregation will write its result to a database collection. + # + # @return [ Boolean ] Whether the aggregation will write its result + # to a collection. + # + # @api private + def write? + pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) } + end + private def server_selector @view.send(:server_selector) end @@ -112,14 +122,10 @@ connection.description end description.standalone? || description.mongos? || description.primary? || secondary_ok? end - def write? - pipeline.any? { |op| op.key?('$out') || op.key?(:$out) || op.key?('$merge') || op.key?(:$merge) } - end - def secondary_ok? !write? end def send_initial_query(server, session) @@ -133,9 +139,24 @@ def validate_collation!(server) if options[:collation] && !server.with_connection { |connection| connection.features }.collation_enabled? raise Error::UnsupportedCollation.new end + end + + # Skip, sort, limit, projection are specified as pipeline stages + # rather than as options. + def cache_options + { + namespace: collection.namespace, + selector: pipeline, + read_concern: view.read_concern, + read_preference: view.read_preference, + collation: options[:collation], + # Aggregations can read documents from more than one collection, + # so they will be cleared on every write operation. + multi_collection: true, + } end end end end end