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

`Mongoid.purge!` and `Mongoid.truncate` ignore global persistence context overrides

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Critical - P2 Critical - P2
    • 7.3.0
    • Affects Version/s: None
    • Component/s: Persistence
    • None
    • Minor Change

      When I useĀ `Mongoid.purge!` and `Mongoid.truncate` I would expect the method to use the `Mongoid.override_database`
      Example

      require 'mongoid'
      
      Mongoid.connect_to 'bugs'
      
      class Something
        include Mongoid::Document
      
        field :doesnt_matter, type: String, default: ''
      end
      
      
      puts "----Testing purge!----"
      Something.create!(doesnt_matter: 'test-purge')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.purge!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      puts "----Testing truncate!----"
      Something.create!(doesnt_matter: 'test-truncate')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.truncate!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      Mongoid.override_database('bugs_1')
      
      puts "----Testing purge! with override db----"
      Something.create!(doesnt_matter: 'test-purge-ov')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.purge!
      puts "  Expect: 0, Actual: #{Something.count}"
      
      puts "----Testing truncate! with override db----"
      Something.create!(doesnt_matter: 'test-truncate-ov')
      puts "  Expect: 1, Actual: #{Something.count}"
      Mongoid.truncate!
      puts "  Expect: 0, Actual: #{Something.count}"
      

            Assignee:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Reporter:
            jonathag@cisco.com Jonathon Gardner
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: