1

I've found that in order to create an index in a collection I should use the indexesManager:

collection.indexesManager.ensure(...)

I would like to know which is the right place for this function call.

I put this call in the function of the Controller that performs the insertion of documents in the collection, and it works. But I guess that it is not necessary to call this function on each insertion.

Is there a way to make this call only once when the DB is initialized?

Thanks

tano
  • 836
  • 1
  • 10
  • 25

1 Answers1

0

In reactivemongo 2.11, you should be able to get the current database instance like this :

val db = current.injector.instanceOf[ReactiveMongoApi].database

Please note that this line will give you back a Future[DefaultDB]. Then, you can do what you want by simply mapping on this Future :

db.map(_.collection("myCollection")))

ersefuril
  • 809
  • 9
  • 16