James
James

Reputation: 229

Casbah returns DBObject instead of MongoDBObject

In the official Casbah guide on querying it says

findOne Returns an Option - either Some(MongoDBObject) or None

However, findOne actually gives me an Option with a plain Some(DBObject) instead:

scala> MongoClient("localhost", 27017)("db")("collection").findOne()

res0: Option[com.mongodb.DBObject] = Some({ "_id" : { "$oid" : "559860491b07c0dc5b52f3ee"} , "description" : "Some text" })

The same happens with find, it returns an iterator over DBObject instances. After hours of googling and scratching my head I'm at a loss.

What's going on here? I'm still learning Scala so there might be some nuance that I'm not getting.

Upvotes: 0

Views: 746

Answers (1)

DNA
DNA

Reputation: 42597

The examples in the tutorial return plain DBObjects, so I think this is just a mistake in the documentation.

Casbah provides implicit (automatic) conversions between DBObject and MongoDBObject - as described here:

There is an implicit conversion loaded that can Pimp any DBObject as MongoDBObject

We automatically provide implicit methods which convert DBObject to MongoDBObject. Any method which needs a MongoDBObject will accept a DBObject fine as long as you ran the imports.

You will need to import the conversions for this to work, using:

import com.mongodb.casbah.Imports._

Upvotes: 1

Related Questions