Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a unique index for a collection in reactivemongo

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?

like image 203
Jordan Avatar asked Mar 20 '23 19:03

Jordan


1 Answers

You can access the IndexManager from your BSONCollection:

collection.indexesManager.ensure(...)

See reactivemongo docs for details:

  • 0.9 (as of Jan 2019 - gives 404)
  • 0.1x (as of Jan 2019 - current version)
like image 51
vptheron Avatar answered Apr 24 '23 00:04

vptheron