Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-1995

Dependent Behavior: "delete" too inefficient?

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.4.10
    • Affects Version/s: None
    • Component/s: None

      I've got a class that looks like this:

      class Person
        include Mongoid::Document
        has_many :lots_of_freaking_documents, dependent: :delete
        # ^ about a 500k documents related to this person.
      end
      

      When I do this:

      person = Person.find(...)
      person.destroy
      

      Instead of just deleting all of of the "lots_of_many_freaking_documents" based on the person_id field, Mongoid seems to be iterating through the "lots_of_many_freaking_documents" relationship, loading them and one by one removing them from the collection, which takes it a very, very long time.

      Shouldn't Mongoid just be doing the equivalent of person.lots_of_many_freaking_documents.delete_all for this kind of dependent behavior? Am I missing something here with how this is supposed to work?

            Assignee:
            Unassigned Unassigned
            Reporter:
            radicaled Arron Washington
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: