Mounted file from Mongoid::Paranoia document is hard deleted #41

merged 1 commit into from Feb 11, 2013


None yet

4 participants



I have mounted an uploader in a document with Mongoid::Paranoia included, to prevent hard deletes. But while the document is softly deleted (i.e. has the deleted_at field set), its mounted file is hard deleted. This makes Mongoid::Paranoia useless when combined with Carrierwave.

  class MyDocument
    include Mongoid::Document
    include Mongoid::Paranoia
    mount_uploader :media, MyUploader

    # ...
CarrierWave member

This is similar to carrierwaveuploader/carrierwave#624. Given the nature of the dependency, I don't think this is something that carrierwave-mongoid (or carrierwave) should be responsible for.

In your document, try something like this:

skip_callback :destroy, :after, :remove_media!
@rmm5t rmm5t closed this Apr 29, 2012
@rmm5t rmm5t reopened this Apr 29, 2012
CarrierWave member

I'm going to take back my original statement for now and instead think about it some more. Upon further review, this is slightly different than carrierwaveuploader/carrierwave#624 because acts_as_paranoid is a third party dependency while Mongoid::Paranoid is built into Mongoid.

Meanwhile, the skip_callback workaround should suffice.


Thanks. I'm overriding remove!() with an empty method in the uploader right now, which seems to work, but it would be nice to not have to work around it.


@rmm5t The skip_callback :destroy, :after, :remove_media! seems to not work...

@ghostganz Hi, could you show how did you work around? Thanks


I'm doing it like this:

class MediaUploader < CarrierWave::Uploader::Base
  include CarrierWave::MimeTypes
  storage :grid_fs

  def store_dir

  def remove!(*args)
    # no-op override

Thanks, @ghostganz, i'll give a try. Actually I have found this gist too:


Similarly, if I already have a Mongoid document that is deleted (using Mongoid::Paranoia), and then try to upload an attachment with carrierwave and carrierwave-mongoid, the upload is done but the identifier doesn't get written to the document.

It looks like the document's changes array is empty right before save, so the new value doesn't get saved. Still investigating, but have you guys seen this?

@rmm5t rmm5t Added Mongoid::Paranoia support
Mounted uploaders are kept around if the document is paranoid
@rmm5t rmm5t merged commit 8c42e27 into master Feb 11, 2013

1 check passed

Details default The Travis build passed
CarrierWave member

Could everyone please confirm that the new paranoia support that was just added resolves the underlying issue?

gem "carrierwave-mongoid", git: "git://"

I'll release a new official carrierwave-mongoid release soon after.

CarrierWave member

Just checking back in with everyone on this issue. If I don't hear back from anyone, I'll assume that the code changes attached to this issue resolve everyone's Mongoid::Paranoia problems but might wait for another feature or fix before issuing a new official release. On the other hand, if people would benefit from a new release, I'm glad to do that, but only after getting confirmation that this fully resolves the underlying issue.


I'm stuck on an old version, because of the massive changes needed to go to Mongoid 3, so I won't be able to verify the fix.
I'd be happy if you have a release out by the time we've done the leap to Mongoid 3. :)

CarrierWave member

@ghostganz I just back ported the paranoia support to the v0.2 line. See carrierwave-mongoid v0.2.2. If any issues, please submit a pull request against the 0.2-stable branch.

Everyone else, there's now a new v0.5.0 release that support Mongoid::Paranoia under Mongoid ~>3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment