Questions tagged [casbah]

Casbah integrates a Scala toolkit layer on top of the official MongoDB Java driver.

Casbah is end-of-life (EOL):

Users are encouraged to migrate to the Mongo Scala Driver for a modern idiomatic MongoDB Scala driver.

Casbah is a Scala toolkit for MongoDB. We use the term “toolkit” rather than “driver”, as Casbah integrates a layer on top of the official mongo-java-driver for better integration with Scala. This is as opposed to a native implementation of the Mongo Wire Protocol, which the Java driver does exceptionally well. Rather than a complete rewrite, Casbah uses implicits and Pimp My Library code to enhance the existing Java code with fluid, Scala-friendly syntax.

Documentation and source code

Related Links

266 questions
1
vote
1 answer

MongoDb. Extracting integer from database. java.lang.Integer cannot be cast to java.lang.String

I am new to MongoDb. I was trying to retreive data from the db. Here is part of my code: dbc(TABLENAME).find ( MongoDBObject (UID -> uid)).toList.foreach {s => val Rollno = s.getAs[String](ROLL).getOrElse ("?") Apparently ROLL is set as…
1
vote
3 answers

casbah mongodb more typesafe way to access object parameters

In casbah, there are two methods called .getAs and .getAsOrElse in MongoDBObject, which returns the relevant fields' values in the type which given as the type parameter. val dbo:MongoDBObject = ... dbo.getAs[String](param) This must be using type…
tiran
  • 2,389
  • 1
  • 16
  • 28
1
vote
2 answers

How do I create a Mongo replicaset connection with Casbah?

I am a newbie to scala and casbah. I am trying to create a mongo replicaset connection using casbah. This is my code. I am pretty sure about my mongo replica setup being correct. When I create a connection through ruby, it works great. Im missing…
Deepak
  • 2,481
  • 2
  • 23
  • 28
1
vote
1 answer

Casbah Scala MongoDB driver - a strange error

I am trying to use Casbah, I get a strange error right in the beginning, on this line: val mongoDB = MongoConnection("MyDatabase") the error on MongoConenction says: class file needed by MongoConnection is missing. reference type MongoOptions of…
noncom
  • 4,962
  • 3
  • 42
  • 70
1
vote
1 answer

Cannot get a basic Casbah 3.0 program to compile

My project uses the following jars: scala-library (2.9.2), mongo-java-driver (2.7.3), scalaj-collection (2.9.1-1.2), casbah (util, commons, core, query, gridfs) 2.9.1-3.0.0-M2, joda-time 2.1, and joda convert 1.2 When I enter the following…
Eduardo
  • 8,362
  • 6
  • 38
  • 72
0
votes
2 answers

How to parse a json with date exported by mongoexport in Scala?

Given this code example: import com.mongodb.util.JSON import com.mongodb.casbah.Imports._ val json = """{"date" : { "$date" : 1327064009959 }}""" val doc = JSON.parse(json) I get this error: java.lang.ClassCastException: java.lang.Long cannot be…
Piotr Zolnierek
  • 1,030
  • 1
  • 10
  • 19
0
votes
2 answers

How to update/delete an embedded object

Given following domain model: case class Benefits(id: Int, benefitPlan: String, comment : String) case class Employee(empNum : Int, benefits : List[Benefit]) I've been using Salat to help derialize/deserialize these objects. However, I'm a little…
cracked_all
  • 1,331
  • 1
  • 11
  • 26
0
votes
2 answers

Querying by Comparing to ObjectId

I have val maxId = new ObjectId(...) and I want to query something like this: collection.find("_id" $lte maxId). This is a compilation failure since ObjectId doesn't include the appropriate trait ValidDateOrNumericType. How to properly query objects…
hleinone
  • 4,470
  • 4
  • 35
  • 49
0
votes
1 answer

using the oplog monitoring class in casbah

I am trying to use the oplog monitoring class in casbah https://github.com/mongodb/casbah/blob/master/casbah-core/src/main/scala/util/OpLog.scala What i want to do is monitor the oplog entries at a production mongo db on …
swordfish
  • 4,899
  • 5
  • 33
  • 61
0
votes
1 answer

Scala: java.lang.VerifyError - Incompatible argument to function - runtime error

I'm using the MongoDB Casbah libraries for Scala on a mixed Java/Scala project. This code works fine in the REPL: studentCollection.distinct("districtlea").foreach(x => { println(x) val q = MongoDBObject("districtlea" -> x) val…
brandon
  • 675
  • 6
  • 10
0
votes
1 answer

What is the performance impact of using Casbah as opposed to directly using MongoDb java driver?

Casbah is another layer on top of Java driver for MongoDb. Would this reduce performance of queries and updates in MongoDb database in scala projects when using Casbah as opposed to directly using the Java driver?
ace
  • 11,526
  • 39
  • 113
  • 193
0
votes
0 answers

casbah_2.12 cannot work with MongoDB 4.0.0

I have a Spark job which reads data from MongoDB, everything is fine when I connect to MongoDB 3.x, But when I upgrade to MongoDB 4.x, runtime error happens. now my spark & casbah version is as follows(all are of latest…
alexpeng
  • 13
  • 2
0
votes
1 answer

How to get error message from the scala/java MongoDB api

I'm using Casbah (mongodb scala library). I have an insert that doesn't work. val builder = MongoDBObject.newBuilder builder += "_id" -> token.uuid builder += "email" -> token.email builder += "creationTime" -> token.creationTime builder +=…
John Smith Optional
  • 22,259
  • 12
  • 43
  • 61
0
votes
0 answers

Aggregate very slow Scala

I need help because I don't know why my aggregate is very slow. I have one database with 2 collections : users (id, name, email) with 40 000 elements posts (id, author, content) with 39 000 elements I want to know all post posted by an user. I use…
Ned Z
  • 9
  • 1
0
votes
0 answers

Query based on date range behaving differently on Mongo CLI and Casbah

The following query works on Mongo CLI, but not on Casbah API. The query: db.collection.aggregate([ {$unwind:'$views'}, {$project:{'views': 1}}, {$match:{'views.date':{$gte: ISODate('2017-06-01T00:00:00.000Z'), $lt:…
Fernando Lemos
  • 297
  • 3
  • 9