Method: Mongoid::Contextual::Memory#delete

Defined in:
lib/mongoid/contextual/memory.rb

#deletenil Also known as: delete_all

Delete all documents in the database that match the selector.

Examples:

Delete all the documents.

context.delete

Returns:

  • (nil)

    Nil.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/mongoid/contextual/memory.rb', line 46

def delete
  deleted = count
  removed = map do |doc|
    prepare_remove(doc)
    doc.send(:as_attributes)
  end
  unless removed.empty?
    collection.find(selector).update_one(
      positionally(selector, "$pullAll" => { path => removed }),
      session: _session
    )
  end
  deleted
end