Method: Mongoid::Persistence::ClassMethods#destroy_all

Defined in:
lib/mongoid/persistence.rb

#destroy_all(conditions = {}) ⇒ Object

Delete all documents given the supplied conditions. If no conditions are passed, the entire collection will be dropped for performance benefits. Fires the destroy callbacks if conditions were passed.

Example:

Person.destroy_all(:conditions => { :title => "Sir" }) Person.destroy_all

Returns: true or raises an error.



210
211
212
213
214
# File 'lib/mongoid/persistence.rb', line 210

def destroy_all(conditions = {})
  documents = all(conditions)
  count = documents.count
  documents.each { |doc| doc.destroy }; count
end