Given the following data structure:
{
"_id" : ObjectId("55760212e4b011ee8c72fb1f"),
"firstname" : "joe",
"lastname" : "blow",
"email" : "jb@gmail.com",
"sysadmin" : false,
"siteadmin" : false,
"sites" : [
{
"siteId" : ObjectId("55760212e4b011ee8c72fb1e"),
"notification" : false
}
]
}
I'm trying to $pull
a nested sites
object using an ObjectId
as search criteria. The following code:
val siteSearch = MongoDBObject("siteId" -> siteId)
val query = MongoDBObject("sites" -> siteSearch)
db(collection).update(query, $pull(query))
generates for following query
{ "sites" : { "siteId" : { "$oid" : "55760212e4b011ee8c72fb1e"}}}
It's not removing the site, I'm assuming because I want the query
to look like:
{ "sites" : { "siteId" : ObjectId("55760212e4b011ee8c72fb1e")}}
I'm not sure how to make Cashbah issue the correct query.