wipman
wipman

Reputation: 581

Querying for a field inside another

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.

Upvotes: 1

Views: 46

Answers (1)

Vishwas
Vishwas

Reputation: 7067

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"))

Upvotes: 1

Related Questions