You can access the IndexManager from your BSONCollection:
collection.indexesManager.ensure(...)
See reactivemongo docs for details:
Question
Looking at the MongoDB documentation it looks like you can ensure an index is created for a collection at application runtime using a command that looks something like this:
db.myCollection.ensureIndex({'my-col': 1}, {unique: true})
I can't find anything like this in the reactive mongo apis. Does such a thing exist?
OTHER TIPS
As of libraryDependencies += "org.reactivemongo" %% "play2-reactivemongo" % "0.20.3-play28"
1st define the index
val createdTSInx = Index(
key = Seq("createdTS" -> IndexType.Ascending),
name = Some("createdTSInx"),
unique = true,
background = false,
sparse = false,
expireAfterSeconds = None,
storageEngine = None,
weights = None,
defaultLanguage = None,
languageOverride = None,
textIndexVersion = None,
sphereIndexVersion = None,
bits = None,
min = None,
max = None,
bucketSize = None,
collation = None,
wildcardProjection = None,
version = None,
partialFilter = None,
options = BSONDocument.empty)
// to create
collection.indexesManager.create(createdTSInx)
//to ensure
collection.indexesManager.ensure(createdTSInx)