DeleteBuilder

reactivemongo.api.collections.DeleteOps.DeleteBuilder
sealed trait DeleteBuilder

Builder for delete operations.

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any

Members list

Concise view

Value members

Abstract methods

the ordered behaviour

the ordered behaviour

Attributes

the writer concern to be used

the writer concern to be used

Attributes

Concrete methods

final def element[Q, U](q: Q, limit: Option[Int], collation: Option[Collation])(implicit qw: Writer[Q]): Future[DeleteElement]

Prepares an DeleteElement.

Prepares an DeleteElement.

Attributes

collation

the collation

limit

the maximum number of documents

q

the query/selector

See also:

Performs a bulk operation using many deletes, each can delete multiple documents.

Performs a bulk operation using many deletes, each can delete multiple documents.

import scala.concurrent.{ ExecutionContext, Future }

import reactivemongo.api.bson.BSONDocument
import reactivemongo.api.bson.collection.BSONCollection

def bulkDelete(
 coll: BSONCollection,
 docs: Iterable[BSONDocument])(implicit ec: ExecutionContext) = {
 val delete = coll.delete(ordered = true)
 val elements = Future.sequence(docs.map { doc =>
   delete.element(
     q = doc,
     limit = Some(1)) // only first match
 })

 elements.flatMap { ops =>
   delete.many(ops) // Future[MultiBulkWriteResult]
 }
}

Attributes

final def one[Q, U](q: Q, limit: Option[Int], collation: Option[Collation])(implicit ec: ExecutionContext, qw: Writer[Q]): Future[WriteResult]

Performs a delete with a one single selector (see DeleteElement). This will delete all the documents matched by the q selector.

Performs a delete with a one single selector (see DeleteElement). This will delete all the documents matched by the q selector.

Attributes

collation

the collation

limit

the maximum number of documents

q

the query/selector