Creates the given index.
Creates the given index.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.CollectionMetaCommands import reactivemongo.api.indexes.Index def createIndexes( coll: CollectionMetaCommands, is: Seq[Index])( implicit ec: ExecutionContext): Future[Unit] = Future.sequence( is.map(idx => coll.indexesManager.create(idx))).map(_ => {})
_Warning_: given the options you choose, and the data to index, it can be a long and blocking operation on the database. You should really consider reading http://www.mongodb.org/display/DOCS/Indexes before doing this, especially in production.
the index to create
Drops the given index on that collection.
Drops the given index on that collection.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.CollectionMetaCommands def dropIndex(coll: CollectionMetaCommands, name: String)( implicit ec: ExecutionContext): Future[Int] = coll.indexesManager.drop(name)
the name of the index to be dropped
The number of indexes that were dropped.
Drops all the indexes on that collection.
Drops all the indexes on that collection.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.CollectionMetaCommands def dropAllIndexes(coll: CollectionMetaCommands)( implicit ec: ExecutionContext): Future[Int] = coll.indexesManager.dropAll()
The number of indexes that were dropped.
Creates the given index only if it does not exist on this collection.
Creates the given index only if it does not exist on this collection.
The following rules are used to check the matching index:
- if nsIndex.isDefined
, it checks using the index name,
- otherwise it checks using the key.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.CollectionMetaCommands import reactivemongo.api.indexes.Index def ensureIndexes( coll: CollectionMetaCommands, is: Seq[Index])( implicit ec: ExecutionContext): Future[Unit] = Future.sequence( is.map(idx => coll.indexesManager.ensure(idx))).map(_ => {})
_Warning_: given the options you choose, and the data to index, it can be a long and blocking operation on the database. You should really consider reading http://www.mongodb.org/display/DOCS/Indexes before doing this, especially in production.
the index to create
true if the index was created, false if it already exists.
Lists the indexes for the current collection.
Lists the indexes for the current collection.
import scala.concurrent.{ ExecutionContext, Future } import reactivemongo.api.CollectionMetaCommands def listIndexes(coll: CollectionMetaCommands)( implicit ec: ExecutionContext): Future[List[String]] = coll.indexesManager.list().map(_.flatMap { idx => idx.name.toList })