lib/mongoid/contextual/mongo.rb in mongoid-6.3.0 vs lib/mongoid/contextual/mongo.rb in mongoid-6.4.0

- old
+ new

@@ -93,11 +93,12 @@ # # @since 3.0.0 def destroy each.inject(0) do |count, doc| doc.destroy - count += 1 + count += 1 if acknowledged_write? + count end end alias :destroy_all :destroy # Get the distinct values in the db for the provided field. @@ -338,11 +339,11 @@ # @since 3.0.0 def initialize(criteria) @criteria, @klass, @cache = criteria, criteria.klass, criteria.options[:cache] @collection = @klass.collection criteria.send(:merge_type_selection) - @view = collection.find(criteria.selector) + @view = collection.find(criteria.selector, session: session) apply_options end delegate(:database_field_name, to: :@klass) @@ -701,9 +702,17 @@ def yield_document(document, &block) doc = document.respond_to?(:_id) ? document : Factory.from_db(klass, document, criteria.options[:fields]) yield(doc) documents.push(doc) if cacheable? + end + + def session + @criteria.send(:session) + end + + def acknowledged_write? + collection.write_concern.nil? || collection.write_concern.acknowledged? end end end end