3

I'm trying to use casbah's fluid querying in find().

My data is like this:

{ "_id" : ObjectId("4d7b26efc58bf2b18f14d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06sfnt9" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19014d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06fqp8" ] }
{ "_id" : ObjectId("4d7b26efc58bf2b19114d9cd"), "srcID" : [ "/m/05zppz" ], "relation" : [ "/location/location/people_born_here" ], "dstID" : [ "/m/06_7xfd" ] }

I wrote the following code to query this:

val srcIDs:List[String] = List("/m/05zppz", "/m/06sfnt9")
val query = "srcID" $in srcIDs

the code segment does not compile and reports this error:

error: value $in is not a member of java.lang.String
query = ("srcID" $in srcIDs)

The casbah documentation has the above syntax for $in, but it doesn't seem to work. How to make the $in query work? As a matter of fact, I could not get any fluid query with Casbah's DSL to work and they fail giving the same error msg. Please help!

Taryn
  • 242,637
  • 56
  • 362
  • 405
  • 1
    Just an FYI since you are new to the site: a little bit of formatting goes a long way. You can see a preview of your post as you type, too! – Dylan Aug 05 '11 at 18:04

2 Answers2

4

The problem is that $in is not a method defined on strings. Most likely Casbah defines an implicit conversion from String objects to instances of a class that contain the method $in. The implicit conversion needs to be imported into scope before it can be used.

Could you point us to the Casbah documentation that introduces the $in method? That's where we will find what needs to be imported.

(For the experts: isn't $ supposed to be reserved for compiler generated fields?)

Kipton Barros
  • 21,002
  • 4
  • 67
  • 80
3

I fixed it! You reply was very helpful. I had missed the import statement needed for implicit conversion and hence it was treating it as a String.

I included import com.mongodb.casbah.Imports._ and it works like a charm now. Thanks for the hint!

spydon
  • 9,372
  • 6
  • 33
  • 63
user631089
  • 31
  • 1