casbah

How to customize serialization behavior without annotations in Salat?

女生的网名这么多〃 提交于 2019-12-13 00:55:26
问题 I'm using Salat library to serialize objects to be stored in MongoDb via Casbah. Sometimes I need to tune little bit how fields will be serialized, and Salat's Annotations is a pretty convenient way to do it. BUT, Is there any way to describe serialization parameters(Key, Ignore etc) not directly in case-classes(models) via Annotations, but in some external point, to keep my models clear from Salat dependency(aka POJO/POCO)? 回答1: Yes, you can add custom serialization logic to your Salat

Howto test Custom Json Objects with Spray Routing

时光怂恿深爱的人放手 提交于 2019-12-12 14:22:59
问题 I'm creating a Rest API with spray-routing on top of mongodb for some CRUD operations, this all works fine, expect whenever I try to test it with specs2 the following specification class RestServiceSpec extends Specification with Specs2RouteTest with RoutingRestService // database initialization removed for clarity "The rest service" should "have a player called 'Theo TestPlayer' in the db" in { Get("/api/1.0/player/" + player1._id) ~> restRoute ~> check { entityAs[Player] must be equalTo

resolviing SBT dependencies

寵の児 提交于 2019-12-12 03:18:38
问题 I am new to JVM development (I am using Scala and SBT) and am having trouble resolving dependencies. Yesterday, I had trouble resolving the org.restlet.2.1.1 dependency and today, I am having trouble with resolving the following: [error] (*:update) sbt.ResolveException: unresolved dependency: com.mongodb.casbah#casbah_2.9.2;2.1.5-1: not found [error] unresolved dependency: org.scalatra#scalatra_2.9.2;2.3.0: not found [error] unresolved dependency: org.scalatra#scalatra-akka2_2.9.2;2.3.0: not

Convert MongoDBObject to JsValue

心已入冬 提交于 2019-12-11 19:42:30
问题 Let's say I have .... val obj: MongoDBObject = getDbObj println(obj) prints out: { "_id" : "1234", "name":"Kevin", "age":"100" } How can I convert obj to a JsValue ? 回答1: This is how you do it for Play 2.1 (documentation) val dbo = MongoDBObject("id" -> "0001", "name" -> "Kevin", "age" -> "100") val json: JsValue = Json.parse(dbo.toString) 来源: https://stackoverflow.com/questions/18747315/convert-mongodbobject-to-jsvalue

NoClassDefFoundError => ClassPath$JavaContext when using play start

末鹿安然 提交于 2019-12-11 03:22:05
问题 I've made a little Scala, Play2.0.2 application. It works fine when i use play run command, but when i use play start or play clean compile stage + target/start , when trying to do a MongoDB insertion with Casbah/Salat, i get the following stack: [info] application - Can't create user java.lang.NoClassDefFoundError: scala/tools/nsc/util/ClassPath$JavaContext at scala.tools.scalap.scalax.rules.scalasig.ScalaSigParser$.scalaSigFromAttribute(ScalaSig.scala:35) ~[scalap-2.9.1.jar:na] at scala

Scala, Casbah - How to convert List to MongoDBList?

前提是你 提交于 2019-12-10 13:58:00
问题 Is there an easy way to turn List into MongoDBList(or BasicDBList) ? 回答1: scala> val list = List("foo", "bar") list: List[java.lang.String] = List(foo, bar) scala> val dbList = MongoDBList(list:_*) dbList: com.mongodb.casbah.commons.MongoDBList = [ "foo" , "bar"] Hint: always read source code at first. It can provide many answers to your questions and will be useful BTW. It may be hard at first time, but then it became more and more natural. 来源: https://stackoverflow.com/questions/15188605

MongoDB Scala Driver - Rendering BSON Documents

大憨熊 提交于 2019-12-10 09:57:35
问题 We currently have a Type-Safe query language at work, this custom DSL allows us to easily write database queries that are interpreted and converted into Mongo Queries. We recently swapped over from Casbah to the new Mongo Scala Driver and rewrote our interpreter. I am however having some issues when dealing with optional values. This is an example query: dao.headOption(Order.id === orderId.some) The type stored on the Order Object is an Option so we lift the provided id into an option as well

How to pool the connections of mongodb with casbah?

筅森魡賤 提交于 2019-12-08 15:27:23
问题 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? 回答1: Casbah wraps the MongoDB Java Driver which provides a connection pool. An Instance of MongoConnection is actually an instance of the pool, not an individual connection. The pool can be tuned with an instance of the MongoOptions class passed to a new MongoConnection. 来源: https://stackoverflow.com

Executing custom function on MongoDB using Casbah/Scala

房东的猫 提交于 2019-12-08 00:46:31
问题 I've defined a function in MongoDB using its command line client. function something(){...} I was wondering how can I execute a custom MongoDB function using casbah from Scala. Any recommendations ? Thanks, 回答1: There are a few ways to run arbitrary javascript code on the server. You can supply it as a string from the client and send it to the server for evaluation, or install the function on the server first, as documented here: http://docs.mongodb.org/manual/core/server-side-javascript/

Executing custom function on MongoDB using Casbah/Scala

折月煮酒 提交于 2019-12-06 11:47:06
I've defined a function in MongoDB using its command line client. function something(){...} I was wondering how can I execute a custom MongoDB function using casbah from Scala. Any recommendations ? Thanks, There are a few ways to run arbitrary javascript code on the server. You can supply it as a string from the client and send it to the server for evaluation, or install the function on the server first, as documented here: http://docs.mongodb.org/manual/core/server-side-javascript/ Server-side functions are registered per db, in a collection called system.js. Either way, you can then use the