Method: Mongoid::Relations::Embedded::Batchable#batch_remove

Defined in:
lib/mongoid/relations/embedded/batchable.rb

#batch_remove(docs, method = :delete) ⇒ Object

Batch remove the provided documents as a $pullAll.

Examples:

Batch remove the documents.

batchable.batch_remove([ doc_one, doc_two ])

Parameters:

  • docs (Array<Document>)

    The docs to remove.

  • method (Symbol) (defaults to: :delete)

    Delete or destroy.

Since:

  • 3.0.0



57
58
59
60
61
62
63
64
65
66
# File 'lib/mongoid/relations/embedded/batchable.rb', line 57

def batch_remove(docs, method = :delete)
  removals = pre_process_batch_remove(docs, method)
  if !docs.empty?
    collection.find(selector).update(
      positionally(selector, "$pullAll" => { path => removals })
    )
    post_process_batch_remove(docs, method)
  end
  reindex
end