MongoDB Java / Scala drivers - Missing methods

452 Views Asked by At

I'm trying to convert a persistence layer from a plain old database (using ScalaQuery) to MongoDB, and I'm running into an odd issue. I use the Casbah driver, which is a Scala wrapper around the official MongoDB Java driver. Both the Java and Scala driver define - according to the docs and the overview of the .jar when I open it in Eclipse - a method findOneById that takes a single DBObject as parameter (with an ID in it).

However, when I try to access it, I get a missing method exception from the Scala compiler, both in Eclipse and SBT - Scala version 2.9.0-1, SBT 0.10.1.

What might cause this? Is this perhaps a known SBT / Scala compiler bug?

I just removed my entire repository so all dependencies get downloaded freshly, but this didn't fix the problems.

1

There are 1 best solutions below

0
On

Are you sure that you call findOneById on a MongoCollection instance ?

Maybe it's the parameter type that is wrong, as I can see on the documentation (http://api.mongodb.org/scala/casbah/2.1.2/scaladoc/com/mongodb/casbah/MongoCollection.html), findOneById should take an Id of type AnyRef and optionnaly the fields to return.

You should try something like mongoCollection.findOneByID(1.asInstanceOf[Object]).

Regarding BBObject, it seems that it doesn't appear in the list of parameter (except as an implicit parameter useful to convert the fields that you request to a DBObject). Maybe the signature of the method changed since a previous release.

Hope this will help.