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

Reading Huge MongoDB collection from Spark with help of Worker

I want to read a huge MongoDB collection from Spark create an persistent RDD and do further data analysis on it. Is there any way I can read the data from MongoDB faster. Have tried with the approach of MongoDB Java + Casbah Can I use the…
Ajay Gupta
  • 3,192
  • 1
  • 22
  • 30
2
votes
0 answers

How can I iterate over GridFS files with Casbah?

I am using GridFs to save millions of files. When getting a list of all files, large result set causes Mongo to fail. When using python, I deal with this situation through using an empty filter for find(): client = MongoClient("192.168.0.13") db =…
mahonya
  • 9,247
  • 7
  • 39
  • 68
2
votes
1 answer

Why multiple mongodb connecions with Casbah?

I have to manage multiple databases connection to MongoDb, using casbah scala client. I have an approximation that works but open hundreds of connections. I want to save a Map[String, MongoDB] that saves a connection for each database (which is the…
gasparms
  • 3,336
  • 22
  • 26
2
votes
3 answers

Can't resolve casbah as a sbt dependency

I'm getting the following error upon compile: [error] (*:update) sbt.ResolveException: unresolved dependency: org.mongodb#casbah_2.11;2.7.4-SNAPSHOT: not found With this build.sbt file: name := """play-scala""" version := "1.0-SNAPSHOT" lazy val…
Christopher Su
  • 373
  • 3
  • 10
2
votes
1 answer

How to do casbah bulk inserts

In casbah I see the following function defined on a MongoCollection: def insert[A](docs: A*)(implicit dbObjView: (A) ⇒ commons.TypeImports.DBObject, concern: mongodb.WriteConcern = writeConcern, encoder: TypeImports.DBEncoder = ...):…
Greg
  • 10,696
  • 22
  • 68
  • 98
2
votes
2 answers

ReactiveMongo & JSON4S

I'm using JSON4S to parse some JSON strings I'm getting from external APIs. Is there anyway to get JSON entities like there is with the play reactivemongo JSONCollection or the spray-json to reactive mongo converter in sprest? Its easy to use…
NightWolf
  • 7,694
  • 9
  • 74
  • 121
2
votes
1 answer

Automatic Type Conversions in casbah for Bigdecimal

I need to serialize scala.math.BigDecimalvalues using casbah automatic type conversions. I've imported this import com.mongodb.casbah.commons.conversions.scala._ and call those methods within the class. RegisterJodaTimeConversionHelpers() …
Shashika
  • 1,606
  • 6
  • 28
  • 47
2
votes
1 answer

Get ID names of documents using casbah

I my project, I get mongodb data using casbah. val mongoClient = MongoClient() val db = mongoClient("configServerTest") val coll = db(moduleName) val allDocs = coll.find() allDocs.foreach(allDocs => println(allDocs)) The result…
Shashika
  • 1,606
  • 6
  • 28
  • 47
2
votes
1 answer

Casbah Mongo as scala Array: is this the most elegant way?

Folks, Is this the most elegant way to get a scala List out of casbah? trains is a subkey in a doc whose value is an array I was slightly surprised that I had to do the instanceOf and then the asScala to get a first class scala list Could I have…
phatmanace
  • 4,671
  • 3
  • 24
  • 29
2
votes
1 answer

How to get a value as number from Mongodb, casbah

I have a simple code for getting the port number from MongoDB. I use scala and the driver is of course casbah. def getPortNo : Int { val query = MongoDBObject("_id" -> "Store") val data = coll.findOne(query) return data.get("port") …
bula
  • 8,719
  • 5
  • 27
  • 44
2
votes
1 answer

Casbah MongoDB update only certain fields

I'm using Casbah Scala driver to do CRUD operations on the MongoDB database. I would like to update a certain fields in a particular document. I'm using the findAndModify method, but to my surprise, the entire document is rewritten. My original…
joesan
  • 13,963
  • 27
  • 95
  • 232
2
votes
2 answers

Mongo Shell Shows Docs Added, yet Assert Fails in Scalatest

Using scalatest and Casbah, I created a test to load a bunch of documents into Mongo, and then assert that collection.count() > 0. val collection = MongoConnection()(MY_DB)(MY_COLLECTION) collection.dropCollection // clear out any docs from…
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Quick way to insert a structured Map[String,Any] object into mongodb

I have a JSON-like scala object consisting of any recursive collection of: scala.collection.Map[String,Any], scala.collection.Seq[Any], plus the basic types: Int, Float, String, Double, Long, which I receive through a web API. If I try to directly…
user48956
  • 14,850
  • 19
  • 93
  • 154
2
votes
1 answer

Convert Casbah findOne to Map

val db = mongoClient("test") val coll = db("test") val q = MongoDBObject("id" -> 100) val result= coll.findOne(q) How can I convert result to a map of key --> value pairs?
Kevin Meredith
  • 41,036
  • 63
  • 209
  • 384
2
votes
1 answer

Single serialization layer to Json with Casbah/Salat

I am trying to create a serialization layer which allows me to: Store my classes in a MongoDB data source Convert them to JSON to use them in a REST API. Some classes are clearly not case classes (because they are inherited from a Java codebase)…
Edmondo
  • 19,559
  • 13
  • 62
  • 115