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
0
votes
1 answer

Link between MongoDB Casbah and Logback

I have a sbt project, and I work with MongoDB (Driver Casbah). I want to have logs on my application, so I tried to use Logback Framework. It works but I don't understand exactly what my code is doing.. here is my code for logs : def logger =…
Azuken
  • 477
  • 1
  • 9
  • 26
0
votes
1 answer

Recursively Build MongoDBObject

How can I recursively append to a DBObject in Casbah, and then return a single MongoDBObject with each list element appended? Note that the below does not compile or work, but it intends to show my desired code def foo( pairs: List[(String, Int)]):…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

$all Operator in Casbah

Could you please give me an example of how to use the $all operator for my two elemMatch objects? val elemMatch1 = foo() val elemMatch2 = bar() How can I perform the query of $all( elemMatch1, elemMatch2) (all documents where elemMatch1 and…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Mongo Connection Failed In Production

I encountered a production error I hope someone can educate me on. I'm running a MongoDB AMI instance (1000 IOPS) in AWS in a cluster (2 dbs + arbiter). My app server connecting to the database resides on separate instances. After weeks of running…
Greg
  • 10,696
  • 22
  • 68
  • 98
0
votes
1 answer

How to put datas from MongoDB into an object with Casbah and Scala

I want to put in a "User" class datas from MongoDB. find() method doesn't return the type I want. I have a piece of code, I don't know how i can use it : def findUser(username: String) : Option[User] = { var user:Option[User] = None val…
Azuken
  • 477
  • 1
  • 9
  • 26
0
votes
1 answer

shortening MongoDBObject Conversion

one thing I came across is the boilerplate code when querying in a mongodb : def findPagesWithGreaterId(pageid: String, limit: Int): List[Page] = findAsListSortedLimit(MongoDBObject("_id" -> MongoDBObject("$gt" -> new ObjectId(pageid))),…
Stefan Kunze
  • 741
  • 6
  • 15
0
votes
1 answer

Type-unsafe behavior of Casbah

I have an id which is Long. But if I getAs[String], it blindly returns Some(0) instead of None. It checks the presence of the key and not the type. scala> collection res26: com.mongodb.DBObject = { "_id" : { "$oid" : "520f8bf544ae41ec63d02eec"} ,…
Jesvin Jose
  • 22,498
  • 32
  • 109
  • 202
0
votes
1 answer

Lazyloading collection in play-salat

Is it possible to load a collection lazy with Sala? e.g. I have an object like Example 1 (in this case, the whole user list is loaded when retrieving the object) case class Test( @Key("_id") _id: ObjectId = new ObjectId, name: String, …
pichsenmeister
  • 2,132
  • 4
  • 18
  • 34
0
votes
0 answers

Adding JsValue to Mongo

Let's say I have a JsValue. val dbo = MongoDBObject("id" -> "0001", "name" -> "Kevin", "age" -> "100") val json: JsValue = Json.parse(dbo.toString) I tried to insert json via: val obj = MongoDBObject("key" -> json) collection.insert(obj) However,…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
2 answers

Inserting JsNumber into Mongo

When trying to insert a MongoDBObject that contains a JsNumber val obj: DBObject = getDbObj // contains a "JsNumber()" collection.insert(obj) the following error occurs: [error] play - Cannot invoke the action, eventually got an error:…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Scala casbah DSL queries

I'm learning Scala and trying Mongo too. I'm creating a function that receives a Map[String, Any] as a parameter and I would like to return the proper MongoDBObject for it: def parse(query: Map[String, Any]): MongoDBObject = { val result =…
Augusto
  • 1,234
  • 1
  • 16
  • 35
0
votes
1 answer

Convert MongoDBObject to JsValue

Let's say I have .... val obj: MongoDBObject = getDbObj println(obj) prints out: { "_id" : "1234", "name":"Kevin", "age":"100" } How can I convert obj to a JsValue?
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Converting MongoCursor to JSON

Using Casbah, I query Mongo. val mongoClient = MongoClient("localhost", 27017) val db = mongoClient("test") val coll = db("test") val results: MongoCursor = coll.find(builder) var matchedDocuments = List[DBObject]() for(result <- results) { …
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
0
votes
1 answer

Optimal way to read out JSON from MongoDB into a Scalatra API

I have a pre-formatted JSON blob stored as a string in MongoDB as a field in one of collections. Currently in my Scalatra based API, I have a before filter that renders all of my responses with a JSON content type. An example of how I return the…
randombits
  • 47,058
  • 76
  • 251
  • 433
0
votes
1 answer

How to use a case class to deserialize an array of json objects to List[Map[String,String]]

I am having trouble deserializing my case class. Although the serialization works great I can't get back the case class with the correct type for some reason. This is my case class: case class Team( id: ObjectId = new ObjectId, teamType: String…
whitehead1415
  • 435
  • 4
  • 14