casbah

Get a count of total documents with MongoDB when using limit

99封情书 提交于 2019-12-27 11:04:58
问题 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 the limit() function in order for me to also capture the total number of documents in the query so I can pass to that to the client letting them know they'll have to issue an additional request(s) to retrieve the rest of the documents. Is there a way

How to retrieve all objects in a Mongodb collection including the ids?

此生再无相见时 提交于 2019-12-21 17:04:00
问题 I'm using Casbah and Salat to create my own Mongodb dao and am implementing a getAll method like this: val dao: SalatDAO[T, ObjectId] def getAll(): List[T] = dao.find(ref = MongoDBObject()).toList What I want to know is: Is there a better way to retrieve all objects? When I iterate through the objects, I can't find the object's _id. Is it excluded? How do I include it in the list? 回答1: 1°/ The ModelCompanion trait provides a def findAll(): SalatMongoCursor[ObjectType] = dao.find(MongoDBObject

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

流过昼夜 提交于 2019-12-21 07:00:11
问题 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 called java.lang.IllegalArgumentException: response too long: 1634610484 at com.mongodb.Response.(Response.java:40) at com.mongodb.DBPort.go(DBPort.java:110) at com.mongodb.DBPort.go(DBPort.java:75) at com.mongodb.DBPort.call(DBPort.java:65) at com

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

三世轮回 提交于 2019-12-18 03:31:08
问题 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 casbah as follows; object Alerts { def list() : List[DBObject]= { val collection = MongoDatabase.collection; val query = MongoDBObject.empty val order = MongoDBObject("Issue Time:" -> -1) val list = collection.find(query).sort(order).toList list } ..

No Implicit View Available

丶灬走出姿态 提交于 2019-12-14 01:07:21
问题 When trying to bulk load a list of DBObject 's via insert, I get no implicit view available . collection.insert(listObjects) // listObjects is a List[DBObject] [error]Test.scala:139: No implicit view available from List[com.mongodb.casba h.Imports.DBObject] => com.mongodb.casbah.Imports.DBObject. What does this error mean? How can I resolve? Reference: def insert [A] (docs: List[A])(implicit arg0: (A) ⇒ DBObject) : WriteResult 回答1: The method insert will take any List, but to store the data

MongoDBObject not being added to inside of an rrd foreach loop casbah scala apache spark

你离开我真会死。 提交于 2019-12-13 18:26:21
问题 Ok guru's, i've got a problem that doesnt make much sense to me. I am stuck trying to save an object to mongodb that looks like such (roughly) {data:[baseball:[{timestamp (essentially):tweet},{timestamp: another tweet}] football:[{timestamp:footballtweet},{timestamp:differentfootballtweet}] ] timeInterval:"last minute to this minute" ( i'm doing timeseries data) terms:["football","baseball"] } see below on which loop im stuck on. note the issue might have something to do with the rrd expiring

casbah cursor and toList

淺唱寂寞╮ 提交于 2019-12-13 18:17:23
问题 I have a cursor in casbah, returned from a query. If I iterate over the cursor I get a certain number of results, x. If I execute the same query and do a toList on the cursor, I get list of size y, a different number. Why? I'm calling this from a test case that has just wriiten a few hundred rows to the collection using the default WriteConcern. I understand there could be some latency with the write. What I don't understand is the different sizes of the cursor: I iterate vs toList. Aren't

Inserting JsNumber into Mongo

巧了我就是萌 提交于 2019-12-13 07:23:33
问题 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: java.lang.IllegalArgumentException: can't serialize class scala.math.BigDecimal I tried to replace the JsNumber with an Int , but I got the same error. EDIT Error can be reproduced via this test code. Full code in scalatest (https://gist.github.com/kman007us

Casbah Scala Runtime Error

混江龙づ霸主 提交于 2019-12-13 07:09:13
问题 I have a Play framework based webapp which has the following defined in its build.sbt file: .... version := "1.0-SNAPSHOT" resolvers += "Sonatype Snapshots" at "http://oss.sonatype.org/content/repositories/snapshots/" resolvers += "Sonatype Releases" at "https://oss.sonatype.org/content/groups/scala-tools" resolvers += "Novus Releases" at "http://repo.novus.com/releases/" libraryDependencies ++= Seq( jdbc, anorm, cache, "com.mongodb.casbah" % "casbah_2.9.0" % "2.2.0-SNAPSHOT", "com.novus" %%

MongoCursor size is decreasing when it is converted to list using toList

拥有回忆 提交于 2019-12-13 05:09:57
问题 I am having weird issue with mongo cursor. I am using casbah to access Mongo through Scala code. I have following code: val cur = collection.find(MongoDBObject("brand" -> "someBrand") val items = cur.toList.map(dbo => ScalaJack.readDB [ T ] (dbo)) I have 387 item in the db that should be returned with the query above. But it is returning 364 items only. When I checked the size of cur it is 387, but when I checked the size of cur.toList it is 364. I am not sure why doing toList on cursor is