Module: Mongoid::Persistable::Destroyable::ClassMethods
- Defined in:
- lib/mongoid/persistable/destroyable.rb
Overview
Instance Method Summary collapse
-
#destroy_all(conditions = nil) ⇒ Integer
Delete all documents given the supplied conditions.
Instance Method Details
#destroy_all(conditions = nil) ⇒ Integer
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.
45 46 47 48 49 50 51 |
# File 'lib/mongoid/persistable/destroyable.rb', line 45 def destroy_all(conditions = nil) selector = conditions || {} documents = where(selector) destroyed = documents.count documents.each { |doc| doc.destroy } destroyed end |