2013-01-15 81 views
1

嵌套的拉動可以說我有一個簡單的對象使用Scala MongoDB的卡斯巴

{ 
"id":"xyz" 
"answers" : [{ 
    "name" : "Yes", 
    }, { 
    "name" : "No", 
    }] 
} 

我想從陣列

我想這樣的事情沒有多少運氣刪除答案是:

import com.mongodb.casbah.MongoCollection 

val searchObject = MongoDBObject("id"->"xyz"); 
getCollection().update(searchObject,$pull("answers" -> ("name" -> "Yes"))); 

回答

2

您需要聲明("name" -> "Yes")MongoDBObject因爲看:

scala> $pull("answers" -> ("name" -> "Yes")) 
res10: com.mongodb.casbah.query.Imports.DBObject = { "$pull" : { "answers" : [ "name" , "Yes"]}} 
是不是你想要的,你要哪拉子文檔

scala> $pull ("answers" -> MongoDBObject("name" -> "Yes")) 
res11: com.mongodb.casbah.query.Imports.DBObject = { "$pull" : { "answers" : { "name" : "Yes"}}} 
+0

這是否爲您解決問題? – Ross

相關問題