Skip to content

Instantly share code, notes, and snippets.

@fcroiseaux
Last active January 1, 2016 04:59
Show Gist options
  • Save fcroiseaux/8095387 to your computer and use it in GitHub Desktop.
Save fcroiseaux/8095387 to your computer and use it in GitHub Desktop.
Regexp not working with ReactiveMongo ?
// Cette requête retourne bien l'enregistrement
val cursor: Cursor[JsObject] = connections.
find(BSONDocument("lastName" -> BSONString(mask))).
cursor[JsObject]
// Celle ci ne retourne rien ?
val cursor: Cursor[JsObject] = connections.
find(BSONDocument("lastName" -> BSONRegex("/"+mask+"/", "i"))).
cursor[JsObject]
// Celle ci non plus
val cursor: Cursor[JsObject] = connections.
find(BSONDocument("lastName" -> BSONString("/"+mask+"/"))).
cursor[JsObject]
// Je ne sais pas si c'est lié mais sur le prompt mongo
// Ceci fonctionne :
db["connections"].find({lastName: /auph/})
// et ceci pas :
db["connections"].find({lastName: "/auph/"})
@sgodbillon
Copy link

val query =
  // the regex should be surrounded by slashes
  BSONDocument("lastName" -> BSONRegex(mask, "i"))
val cursor = collection.find(query).cursor[JsObject]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment