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

elemMatch Query with $gt and $lt

I'm trying to implement an elemMatch query with $gt and $lt in Casbah. "Testing $gt and $lt in $elemMatch" should "return results" in { val TEST = "test" val db = MongoClient()(TEST) val collection = db(TEST) val obj: JsValue = Json.parse("""{…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
1 answer

$elemMatch in Casbah

For this document structure: _id: 1, records : [{n : "Name", v: "Will"}] How can I perform a $elemMatch Mongo shell query from Casbah? db.coll.find( {records : {$elemMatch : {n: : "Name", v : "Will"} } } ) I tried this from the Casbah code's test…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
1 answer

How do I write a query for mongodb using the casbah driver for scala that uses a substring and checks if the field is in a list of supplied values?

Say I have a table in mongodb with a data structure that looks like this: { _id: "123456", provider: "apple", languageCode: "en-US", data: "some data" } How would I write my query so that i retrieve entries whose FULL language codes…
Donuts
  • 2,185
  • 3
  • 20
  • 31
1
vote
0 answers

Find a file in gridfs via md5

I'm trying to find a file in gridFS via the md5 hash, but don't get it to work. My app is a Play application, therefore I use play salat plugin. This is what I'm doing: val Images = gridFS("Images") val image = new File("
schub
  • 912
  • 1
  • 8
  • 26
1
vote
2 answers

Querying on Date in Mongo

I'm inserting a Mongo doc with the following time-stamp: val format = new java.text.SimpleDateFormat("yyyyMMddHHmmss") format.format(new Date()).toLong Here's what the section looks like from Mongo's shell: "{Timestamp" :…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
1 answer

Inserting Object into Mongo with _id Output

How can I insert a new object into Mongo and get the _id with the inserted document? Desired behavior: val _id: String = coll.insert(someObj) // _id = "_id" of inserted doc
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
2 answers

Extract Data from MongoDBList

How can I get a List(String) from this MongoDBList? val a: MongoDBList = ... // equal to [ { "id" : "0001"} , { "id" : "0017"}] Desired result: List("0001", "0017")
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
1
vote
1 answer

scala case class with casbah. Accept objectid parameter as string or as a objectid

I am kind of new to scala and have not done any programming in java or object oriented programming languages. I have been using this case class to write to the database case class User(id: new ObjectId, name: String) What is the best way to let…
whitehead1415
  • 435
  • 4
  • 14
1
vote
1 answer

MongoDB cross-collection query with casbah

I have two collections like follwoing, customers: {id: 1, name: "foo"} {id: 2, name: "bar"} {id: 3, name: "baz"} flags: {cid: 1} {cid: 3} Then retrieving customers whose flag is on db.customers.find({id: {$in: db.flags.distinct("cid",…
yakamoto
  • 50
  • 10
1
vote
1 answer

Scala, Casbah: Compilation errors. How to instatiate object from external libary?

I am trying to write function that writes data to MongoDB using Casbah toolkit: import com.mongodb.casbah.WriteConcern import ... def saveRecord(rec: MongoDBObject) { mongoColl.insert(rec, WriteConcern) } Casbah defines…
Anton Ashanin
  • 1,817
  • 5
  • 30
  • 43
1
vote
1 answer

Multiple documents update mongodb casbah scala

I have two MongoDB collections promo collection: { "_id" : ObjectId("5115bedc195dcf55d8740f1e"), "curr" : "USD", "desc" : "durable bags.", "endDt" : "2012-08-29T16:04:34-04:00", origPrice" : 1050.99, "qtTotal" : 50, …
user2066049
  • 1,371
  • 1
  • 12
  • 26
1
vote
1 answer

nested pull with scala mongodb casbah

lets say i have a simple object { "id":"xyz" "answers" : [{ "name" : "Yes", }, { "name" : "No", }] } I want to remove answer Yes from the array I'm trying something like this without much luck: import…
user1255162
  • 1,258
  • 2
  • 9
  • 13
1
vote
1 answer

Upsert with increment of embedded object value in MongoDB / Casbah / Scala /

I need to increment the count of an embedded object's value for a property, or create the object property if it doesn't exist, or create the entire record if there isn't one, using Casbah for MongoDB in Scala. Also interested in hearing how to do…
mrjf
  • 1,117
  • 1
  • 12
  • 22
1
vote
3 answers

How to update object in Mongo with an immutable Salat case class

I'm working on a project with Scala, Salat, Casbah, Mongo, Play2, BackboneJS... But it's quite a lot of new things to learn in the same time... I'm ok with Scala but I find my code crappy and I don't really know what's the solution to improve…
Sebastien Lorber
  • 89,644
  • 67
  • 288
  • 419
1
vote
1 answer

Pre-persistence validation for Scala case class using Salat/Casbah

Assuming that I have a Scala case class that is persisted using the Salat/Casbah/Mongo stack, I want to set up pre-persistence validation logic like I could easily do in Rails using ActiveRecord hooks or in Java using JSR 303 bean…
kgx
  • 1,195
  • 3
  • 15
  • 26