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
80
votes
16 answers

Get a count of total documents with MongoDB when using limit

I am interested in optimizing a "pagination" solution I'm working on with MongoDB. My problem is straight forward. I usually limit the number of documents returned using the limit() functionality. This forces me to issue a redundant query without…
randombits
  • 47,058
  • 76
  • 251
  • 433
41
votes
2 answers

Why do I end up with java.lang.IllegalArgumentException for Casbah / Java MongoDB Driver?

I'm seeing a strange issue using the casbah / java driver. I keep running into the following exception when the driver tries to create a response from mongo: Oct 16, 2012 10:45:07 AM com.mongodb.DBTCPConnector$MyPort error SEVERE: MyPort.error…
Bryan
  • 1,431
  • 1
  • 14
  • 19
21
votes
1 answer

Why do my MongoDB simultaneous $push updates fail?

I'm performing a number of updates of the form update( { "uuid": someUuid, "revision.versionNumber": someVersionNumber}, { "$set": { "meta.someId": someId }, "$push": { "meta.someMessages": someMessage } } ) occasionally I see when this is…
Bobby
  • 18,217
  • 15
  • 74
  • 89
15
votes
2 answers

mongodbimport Failure - FailedToParse: Expecting '{': offset:0

I tried to import a 7.4 MB JSON file via ... mongoimport -d mongoimport -c test --file jsonTest.json But I saw this issue. Wed Sep 04 13:08:52.378 exception:BSON representation of supplied JSON is too large: code FailedToParse: FailedToParse:…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
12
votes
2 answers

Connection to CosmosDB through Mongo API fails after idle

We have a Scala server which uses the Java MongoDB driver as wrapped by Casbah. Recently, we switched its database over from an actual MongoDB to Azure CosmosDB, using the Mongo API. This is generally working fine, however every once in a while a…
11
votes
1 answer

How to pool the connections of mongodb with casbah?

I'm using mongodb with scala driver casbah. If I'm not understanding wrong, it doesn't provide connection pool. Is there any pool libraries for casbah, like dbcp/c3p0 for jdbc connections?
Freewind
  • 193,756
  • 157
  • 432
  • 708
11
votes
1 answer

How to upsert document in MongoDB Java driver 3

what is the idiomatic way to upsert a document using version 3 of the mongodb java driver (specifically v3.0.1)? We have a collection for sessions and when a new session gets created or modified, we want to upsert it in one operation - rather than…
rmin
  • 1,018
  • 1
  • 9
  • 18
11
votes
3 answers

How to convert casbah mongodb list to json in scala / play

I'm learning scala and mongodb at present and using the play! framework, so I'm making all sorts of mistakes as I get my head around things. Currently I have a scala object that returns a list of database objects returned from a mongodb query via…
Roger
  • 15,793
  • 4
  • 51
  • 73
10
votes
1 answer

How to clear/drop/empty a MongoDb collection with Casbah

I started using MongoDb in Scala via Casbah but cannot find on the Casbah documentation / google the way to drop the content of a collection. The MongoDd doc says the MongoDb shell command to do so is db.things.remove({}); But how can we achieve…
jolivier
  • 7,380
  • 3
  • 29
  • 47
8
votes
2 answers

How to query a Array[String] for a regexp match?

i try to query MongoDB via Casbah for a field that is a array of strings with a regexp. For example: I have a Maschine with a list of ips, that are stored as string in the fields ips. Now i want to search for all machines that have the subnet…
Odo
  • 209
  • 1
  • 12
8
votes
1 answer

HOW TO Find by Object ID on MongoDB with Casbah?

I'm trying to write a query to find by Object ID with Casbah, it seems trivial but ... I don't find. I tried this: def get(id: Option[String]): User = { val mongoDB : MongoDB = MongoConnection().apply("test") val mongoColl : MongoCollection…
Remy
  • 334
  • 1
  • 4
  • 15
8
votes
1 answer

SocketException in Mongo

I just set up a replica set in Mongo (prod environment). I'm now getting a lot of exceptions like below (clipped). I went into mongo and ran a serverStatus command on my primary mongo node and only have about 300 connections going, so it's hardly…
Greg
  • 10,696
  • 22
  • 68
  • 98
8
votes
3 answers

NoSQL (e.g. MongoDB) or RDMS (e.g. PostgreSQL) for new Scala project?

I'm developing a brand new project in Scala. It's just an application for a bunch of CRUD operations, however, because of some eccentric requirements, Play2 or Lift does not fit the bill, so I'm going to develop the application from the ground up.…
Jack
  • 16,506
  • 19
  • 100
  • 167
7
votes
1 answer

how to cast a Mongo BasicDBList to an immutable scala list

I have a BasicDBList that has been persisted into the database. I am now reading the data and trying to convert the list to an immutable scala list as shown: val collection = mongoFactory.getCollection("tokens") val appId = MongoDBObject("appId"…
gofeddy
  • 579
  • 8
  • 20
7
votes
2 answers

find by regular expression with Casbah

how to use regular expressions at Collection#find(/* HERE */) like: val coll = MongoConnection()("foo")("bar") for(x <- coll.find("name" -> ".*son$".r)) { // some operations... }
singaan
  • 83
  • 3
1
2 3
17 18