2011-02-03 48 views
7

找到如何在Collection#find(/* HERE */)像使用正則表達式:正則表達式與卡斯巴

val coll = MongoConnection()("foo")("bar") 
for(x <- coll.find("name" -> ".*son$".r)) { 
    // some operations... 
} 

回答

14

你接近,你只需要您的包裹中的條件MongoDBObject()

我們不得不在一堆地方推出<key> -> <value>的隱式轉換,因爲它們很難被正確捕獲並破壞其他代碼。

他們可能會回到2.1。

而是執行此操作:

val coll = MongoConnection()("foo")("bar") 
for(x <- coll.find(MongoDBObject("name" -> ".*son$".r))) { 
    // some operations... 
} 
+0

非常感謝你。 – singaan 2011-02-03 18:28:19

相關問題