Questions tagged [mongodb-scala]

MongoDB is a scalable, high-performance, open source, document-oriented database. This tag is used for questions related to the Scala driver for MongoDB.

The Scala Driver Documentation.

40 questions
31
votes
6 answers

mongodb get distinct records

I am using mongoDB in which I have collection of following format. {"id" : 1 , name : x ttm : 23 , val : 5 } {"id" : 1 , name : x ttm : 34 , val : 1 } {"id" : 1 , name : x ttm : 24 , val : 2 } {"id" : 2 , name : x ttm : 56 , val : 3 } {"id" : 2…
Swapnil Sonawane
  • 1,445
  • 3
  • 22
  • 37
9
votes
2 answers

Safe+efficient way to modify Mongo objects while iterating over a cursor?

I've got some code that examines every object in a Mongo collection (iterating over the result of a find() with no parameters), and makes changes to some of them. It seems that this isn't a safe thing to do: my changes are saved, but then when I…
Eli Bishop
  • 216
  • 3
  • 6
8
votes
1 answer

mongo update query given error

Coll.update(condition, new BasicDBObject("$set", data), true, true)) This is my update query in mongodb for some records it gives result as { "err" : null , "updatedExisting" : true , "n" : 1 , "ok" : 1.0} and at that time stored update query…
Swapnil Sonawane
  • 1,445
  • 3
  • 22
  • 37
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
5
votes
3 answers

Best mongodb driver for Play Framework 2.1

what's the best MongoDB driver for Play Framework 2.1? I am trying ReactiveMongo at this moment but I cannot find good documentation in anywhere and I have my doubts about its future development. Which driver is the most popular and…
G A
  • 571
  • 3
  • 6
  • 18
4
votes
1 answer

Mongodb scala driver decode case class with default values

Is it possible some how to convince Mongodb driver to use default values for case class fields if no such field found? Currently getting error: case class TestMe(fieldname:String="defaultVal") org.bson.BsonInvalidOperationException: Missing field:…
Bublik
  • 912
  • 5
  • 15
  • 30
4
votes
4 answers

Printing query results from Mongodb in Scala using mongo-scala-driver

I am trying to print results from a MongoDB query in Scala val mongoClient: MongoClient = MongoClient() val database: MongoDatabase = mongoClient.getDatabase("tableScala") val collection: MongoCollection[Document] =…
vdep
  • 3,541
  • 4
  • 28
  • 54
3
votes
1 answer

MongoDB - Sorting by Reference or 'Foreign Key' (Liftweb, Scala)

I have a user which contains a reference field "o" which points to an organisation: > db.users.findOne() { "o" : ObjectId("4ec3548544ae1b7234548826") } Organisations contain a field "n": > db.organisations.findOne() { "n" : "My organization"…
Sri
  • 5,805
  • 10
  • 50
  • 68
3
votes
1 answer

How to return mongodb ObjectId _id after insertOne with mongodb scala driver

If possible, I would like to return the ObjectId() generated by mongo after insertOne operation def insert(inputDocument : Map[String,Any], databaseName : String, collectionName : String, mongoClient : MongoClient) : Future[Completed] = { …
pksimba
  • 193
  • 2
  • 10
3
votes
1 answer

mongodb ORing and ANDing query

I am using mongoDB database. in which I have collection in below format. { name : name1 , area: a , country : c} { name : name2 , area: b , country : c} { name : name3 , area: a1 , country : c1} { name : name4 , area: b1 , country : c1} i want…
Swapnil Sonawane
  • 1,445
  • 3
  • 22
  • 37
2
votes
1 answer

MongoDB Java / Scala drivers - Missing methods

I'm trying to convert a persistence layer from a plain old database (using ScalaQuery) to MongoDB, and I'm running into an odd issue. I use the Casbah driver, which is a Scala wrapper around the official MongoDB Java driver. Both the Java and Scala…
cthulhu
  • 3,142
  • 2
  • 23
  • 32
2
votes
3 answers

maven throwing error when adding casbah to it

I have added casbah to my dependancies using com.mongodb.casbah casbah_2.8.0 2.1.5.0 Then i just wrote a simple mongo connection statement val…
swordfish
  • 4,899
  • 5
  • 33
  • 61
2
votes
1 answer

Why does MongoDB observeOn not use the specified execution context?

In Scala I have composed two MongoDB observables and made a call to observeOn while passing a custom execution context. The call to observeOn is made on the first observable, but the custom execution context is not propagated to the second…
user499882
  • 85
  • 4
2
votes
0 answers

ScalaObservable.foreach doesn't block?

In the MongoDB Scala driver, ScalaObservable.foreach doesn't block as I expected. Since it returns Unit I can't use .toFuture it to wait either. What's the way idiomatic way to wait? My program is quitting too early. As a workaround I've replaced…
Pengin
  • 4,692
  • 6
  • 36
  • 62
2
votes
1 answer

Future[WriteResult] is Failing with ArrayOutOfBounds exception while using scalatest-embedMongo with reactivemongo scala driver version 0.11.5

I am using scalatest-embedMongo as In-memory version of mongoDB for a Scala application. I have currently upgraded my reactivemongo driver from version 0.10.x to version 0.11.5. The scalatest-embedMongo was working fine with the previous version of…
Manish Mishra
  • 796
  • 6
  • 21
1
2 3