mongoid/mongoid — Issue #1505: delete_all is homicidal
Author: gurgeous
Created: 2011-12-16 21:47:41+00:00
State: open

Guess what this does?

```ruby
Book.delete_all(:title => "The Great Gatsby")
```

A quick check for :conditions would be appreciated. Apparently I'm not the only one to encounter this issue:

http://www.themomorohoax.com/2010/10/27/mongoids-delete-all-is-way-too-epic

Here's my amusing workaround, for posterity:

```ruby
module Mongoid
module Persistence
module ClassMethods
alias :delete_all_old :delete_all

def delete_all(conditions = nil)
selector = (conditions || {})[:conditions] || {}
selector.merge!(:_type => name) if hereditary?

if collection.find(selector).count == collection.count
raise "Are you crazy?!?! Did you forget :conditions?"
end

delete_all_old(conditions)
end
end
end
end
```