[英]Scala Play Salat Aggregate Example
I am using Scala Play 2.x with MongoDB in backend and I must confess that Salat has wonderful support for mongo CRUD operations. 我在后端将MongoDB与Scala Play 2.x结合使用,我必须承认Salat对mongo CRUD操作提供了出色的支持。
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. 但是到目前为止,我还没有找到如何使用SALAT调用mongo聚合函数的好示例,例如$ unwind,$ match,$ group或聚合管道。
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. 更新(替代)我没有找到任何系统地解释SALAT中聚合查询用法的帮助。 So as an work around I also added casbah which has a
因此,作为解决方案,我还添加了casbah
support for AGGREGATE QUERIES in SBT and able to open work in parallel with SALAT. 支持SBT中的AGGREGATE QUERIES,并可以与SALAT并行打开工作。
val appDependencies = Seq(
"se.radley" %% "play-plugins-salat" % "1.3.0",
"org.mongodb" %% "casbah" % "2.6.3"
)
Thanks in advance 提前致谢
My salat version: 我的礼拜版本:
libraryDependencies ++= Seq(
"se.radley" %% "play-plugins-salat" % "1.4.0"
)
The code example: 代码示例:
dao.collection.aggregate(
MongoDBObject(
"$unwind" -> "$tag"
),
MongoDBObject(
"$group" -> MongoDBObject(
"_id" -> "$tags",
"count" -> MongoDBObject("$sum" -> 1)
)
),
MongoDBObject(
"$sort" -> MongoDBObject(
"$post" -> -1
)
),
MongoDBObject(
"$limit" -> 1
)
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.