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

Saving an existing record to a different collection fails silently

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Persistence
    • None

      Given the following code:

      person = Person.first
      person.name = "Different Name"
      Person.with(collection: 'other_people') { person.save! }
      

      I would expect person.save! to raise a DocumentNotFound exception, because the record with the given _id does not exist in the other_people collection.

      What actually happens is that the person.save! line simply fails silently. It raises no exception, but it also does not save the record.

      The same behavior occurs with any sort of update when the record does not exist in the collection:

      # updating directly to a different collection -- silently fails
      Person.with(collection: 'other_people') { person.update!(name: 'Different') }
      
      # deleting and then saving to the same collection
      person.name = 'Different'
      person.destroy
      person.save! # <-- silently fails
      
      person.reload # <-- raises exception because the record does not exist
      

            Assignee:
            Unassigned Unassigned
            Reporter:
            jamis.buck@mongodb.com Jamis Buck
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: