1

I have got this document in myDb.myCollection:

"_id" : ObjectId("55fc0ec8666292b85178c180"),
"firstname" : "george",
"surname" : "abitbol",
"data" : {
    "a" : "secret value",
    "b" : "4"
},
"tags" : "[t]"

How do I query for the b field in data to equal "4"?

I tried this:

val r = myCollection.find({"data.b" -> "4"})

for (d <- r)    
println (d)

But here is the error I get:

No implicit view available from (String, String) => com.mongodb.casbah.commons.TypeImports.DBObject.
wipman
  • 581
  • 6
  • 22

1 Answers1

1

You should import following statements-

import com.mongodb.casbah.Imports._
import com.mongodb.casbah.commons.MongoDBObject

And you should use query something like:

collection.find(MongoDBObject("data.a" -> "4"))
Vishwas
  • 6,967
  • 5
  • 42
  • 69