scala - 使用 Casbah 通过正则表达式查找

标签 scala mongodb casbah mongodb-scala

如何在 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/

相关文章:

scala - 如何从scala中的字符串变量中提取特定文本

node.js - MongoDB NodeJS 驱动程序 : Duplicate key `E11000` extract index name

scala - Casbah Scala MongoDB 驱动程序 - 嵌入式对象

scala - 使用 Casbah/Salat 定义自定义序列化 - 或者将序列化委托(delegate)给成员?

scala - IntelliJ Idea 14 : cannot resolve symbol spark

scala - 倾斜的窗口函数和 Hive 源分区?

scala - 在 Scala.js 中,代码如何检测它是在浏览器窗口中运行还是在 WebWorker 中运行?

node.js - MongoDB atomic "findOrCreate": findOne, 如果不存在则插入,但不更新

python - 从字典列表更新数据库

mongodb - 如何进行casbah批量插入