salat

Scala Play Salat Aggregate Example

送分小仙女□ 提交于 2020-02-02 11:21:58
问题 I am using Scala Play 2.x with MongoDB in backend and I must confess that Salat has wonderful support for mongo CRUD operations. But so far I didn't find any good example of how I can call mongo aggregate function using SALAT like $unwind, $match, $group or aggregate pipeline. For example db.posts.aggregate([ { $unwind :"$tag" }, { $group : { _id :"$tags", count : {$sum :1} } }, { $sort : {$post :-1} }, { $limit :1 } ]) UPDATE (ALTERNATIVE) I didn't find any help which systematically explain

Why do i need Scala compiler at runtime? (Play2/Salat with Scalap dependency)

 ̄綄美尐妖づ 提交于 2020-01-14 13:35:12
问题 I'm using Scala / Mongo / Casbah / Salat / Play2 and when i try to use Salat it seems it has a dependency to Scalap. It works fine when running the application with play run but with play start 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.tools.scalap.scalax.rules

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

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" %%

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

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

Play! framework 2.0 scala - ClassCastException: models.MyModel cannot be cast to models.MyModel

你。 提交于 2019-12-07 12:43:50
问题 This is my first play 2.0 app, and scala is still pretty new to me, so I'm likely making a mistake somewhere. I'm using a pretty new plugin that bundles Salat and Casbah: https://github.com/leon/play-salat I've simplified and renamed everything to make it generic. My view ( views/MyController/search.scala.html ): @(modelList:List[models.MyModel]) @main(title = "Search MyModel") { <table> @for(a <- modelList) { <tr><td>@a.field<td>@a.field2</li> } </table> } My controller ( controllers

Scala Play Salat Aggregate Example

泄露秘密 提交于 2019-12-06 13:47:33
I am using Scala Play 2.x with MongoDB in backend and I must confess that Salat has wonderful support for mongo CRUD operations. But so far I didn't find any good example of how I can call mongo aggregate function using SALAT like $unwind, $match, $group or aggregate pipeline. For example db.posts.aggregate([ { $unwind :"$tag" }, { $group : { _id :"$tags", count : {$sum :1} } }, { $sort : {$post :-1} }, { $limit :1 } ]) UPDATE (ALTERNATIVE) I didn't find any help which systematically explain usage of aggregate query in SALAT. So as an work around I also added casbah which has a support for

Mapping MongoDB documents to case class with types but without embedded documents

被刻印的时光 ゝ 提交于 2019-12-06 08:22:22
问题 Subset looks like an interesting, thin MongoDB wrapper. In one of the examples given, there are Tweets and Users. However, User is a subdocument of Tweet . In classical SQL, this would be normalized into two separate tables with a foreign key from Tweet to User. In MongoDB, this wouldn't necessitate a DBRef , storing the user's ObjectId would be sufficient. Both in Subset and Salat this would result in these case classes: case class Tweet(_id: ObjectId, content: String, userId: ObjectId) case