如何在 Collection#find(/* HERE */)
使用正则表达式,例如:
val coll = MongoConnection()("foo")("bar")
for(x <- coll.find("name" -> ".*son$".r)) {
// some operations...
}
最佳答案
您已经接近了,您只需将条件包含在 MongoDBObject()
中.
我们不得不提取 <key> -> <value>
的隐式转换在很多地方,因为它们很难被正确捕获并且正在破坏其他代码。
他们可能会在 2.1 中回归。
改为这样做:
val coll = MongoConnection()("foo")("bar")
for(x <- coll.find(MongoDBObject("name" -> ".*son$".r))) {
// some operations...
}
关于scala - 使用 Casbah 通过正则表达式查找,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4887838/