If you use the following query
("filename" -> "/name/i".r) or "filename" $regex "/name/i"
this will render
{ "name": { "$regex" : "/name/i" } }
instead of
{ "name" : { "$regex" : /name/i } }
Casbah will recognize the type of the second argument and make the query appropriate. If you send pattern instead of regex like the following:
"filename" -> java.util.regex.Pattern.compile("name", Pattern.CASE_INSENSITIVE)
you will get what you want:
{ "filename" -> { "$regex" : "name", "$options" : "-i" } }