module Mongoid::Persistable::Deletable::ClassMethods

Public Instance Methods

delete_all(conditions = nil) click to toggle source

Delete all documents given the supplied conditions. If no conditions are passed, the entire collection will be dropped for performance benefits. Does not fire any callbacks.

@example Delete matching documents from the collection.

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

@example Delete all documents from the collection.

Person.delete_all

@param [ Hash ] conditions Optional conditions to delete by.

@return [ Integer ] The number of documents deleted.

@since 1.0.0

# File lib/mongoid/persistable/deletable.rb, line 138
def delete_all(conditions = nil)
  selector = conditions || {}
  selector.merge!(_type: name) if hereditary?
  coll = collection
  deleted = coll.find(selector).count
  coll.find(selector).remove_all
  deleted
end