lib/mongoid/contextual/mongo.rb in mongoid-6.4.8 vs lib/mongoid/contextual/mongo.rb in mongoid-7.0.0.beta

- old
+ new

@@ -2,19 +2,19 @@ require "mongoid/contextual/atomic" require "mongoid/contextual/aggregable/mongo" require "mongoid/contextual/command" require "mongoid/contextual/geo_near" require "mongoid/contextual/map_reduce" -require "mongoid/relations/eager" +require "mongoid/association/eager_loadable" module Mongoid module Contextual class Mongo include Enumerable include Aggregable::Mongo include Atomic - include Relations::Eager + include Association::EagerLoadable include Queryable # Options constant. # # @since 5.0.0 @@ -93,12 +93,11 @@ # # @since 3.0.0 def destroy each.inject(0) do |count, doc| doc.destroy - count += 1 if acknowledged_write? - count + count += 1 end end alias :destroy_all :destroy # Get the distinct values in the db for the provided field. @@ -339,11 +338,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, session: _session) + @view = collection.find(criteria.selector) apply_options end delegate(:database_field_name, to: :@klass) @@ -485,38 +484,30 @@ # # @example Update the first matching document. # context.update({ "$set" => { name: "Smiths" }}) # # @param [ Hash ] attributes The new attributes for the document. - # @param [ Hash ] opts The update operation options. # - # @option opts [ Array ] :array_filters A set of filters specifying to which array elements - # an update should apply. - # # @return [ nil, false ] False if no attributes were provided. # # @since 3.0.0 - def update(attributes = nil, opts = {}) - update_documents(attributes, :update_one, opts) + def update(attributes = nil) + update_documents(attributes) end # Update all the matching documents atomically. # # @example Update all the matching documents. # context.update_all({ "$set" => { name: "Smiths" }}) # # @param [ Hash ] attributes The new attributes for each document. - # @param [ Hash ] opts The update operation options. # - # @option opts [ Array ] :array_filters A set of filters specifying to which array elements - # an update should apply. - # # @return [ nil, false ] False if no attributes were provided. # # @since 3.0.0 - def update_all(attributes = nil, opts = {}) - update_documents(attributes, :update_many, opts) + def update_all(attributes = nil) + update_documents(attributes, :update_many) end private # yield the block given or return the cached value @@ -548,14 +539,14 @@ # @param [ Symbol ] method The method to use. # # @return [ true, false ] If the update succeeded. # # @since 3.0.4 - def update_documents(attributes, method = :update_one, opts = {}) + def update_documents(attributes, method = :update_one) return false unless attributes attributes = Hash[attributes.map { |k, v| [klass.database_field_name(k.to_s), v] }] - view.send(method, attributes.__consolidate__(klass), opts) + view.send(method, attributes.__consolidate__(klass)) end # Apply the field limitations. # # @api private @@ -702,17 +693,9 @@ 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