Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ensure-index issue with rx-mongo 0.13.0 (issue #184) #190

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,10 @@ lazy val `akka-persistence-mongo-rxmongo` = (project in file("rxmongo"))
.settings(commonSettings:_*)
.settings(
libraryDependencies ++= Seq(
("org.reactivemongo" %% "reactivemongo" % "0.12.3" % "provided")
("org.reactivemongo" %% "reactivemongo" % "0.13.0" % "provided")
.exclude("com.typesafe.akka","akka-actor_2.11")
.exclude("com.typesafe.akka","akka-actor_2.12"),
("org.reactivemongo" %% "reactivemongo-akkastream" % "0.12.3" % "provided")
("org.reactivemongo" %% "reactivemongo-akkastream" % "0.13.0" % "provided")
.exclude("com.typesafe.akka","akka-actor_2.11")
.exclude("com.typesafe.akka","akka-actor_2.12")
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,12 +193,21 @@ class RxMongoDriver(system: ActorSystem, config: Config, driverProvider: RxMongo

private[mongodb] override def ensureIndex(indexName: String, unique: Boolean, sparse: Boolean, keys: (String, Int)*)(implicit ec: ExecutionContext) = { collection =>
val ky = keys.toSeq.map { case (f, o) => f -> (if (o > 0) IndexType.Ascending else IndexType.Descending) }
collection.flatMap(c => c.indexesManager.ensure(Index(
def ensureIndex(c: BSONCollection) = c.indexesManager.ensure(Index(
key = ky,
background = true,
unique = unique,
sparse = sparse,
name = Some(indexName))).map(_ => c))
name = Some(indexName)))

collection.flatMap(c =>
ensureIndex(c).recoverWith {
case CommandError.Code(26) => //no collection
c.create().recover {
case CommandError.Code(48) => //name exists (race condition)
()
}.flatMap(_ => ensureIndex(c))
}.map(_ => c))
}

override private[mongodb] def cappedCollection(name: String)(implicit ec: ExecutionContext) = {
Expand Down