我在后端使用Scala 2.x和MongoDB,我必须承认Salat对mongo操作有很好的支持。
但到目前为止,我还没有找到任何好的例子来说明如何使用SALAT (如$unwind、$match、$group或聚合管道)调用mongo聚合函数。
例如
db.posts.aggregate([
{
$unwind :"$tag"
},
{ $group :
{
_id :"$tags",
count : {$sum :1}
}
},
{
$sort : {$post :-1}
},
{
$limit :1
}
])UPDATE (ALTERNATIVE) --我没有找到任何帮助来系统地解释SALAT中聚合查询的用法。因此,作为一项工作,我还添加了casbah,它有一个
support for AGGREGATE QUERIES in SBT and able to open work in parallel with SALAT. val appDependencies = Seq(
"se.radley" %% "play-plugins-salat" % "1.3.0",
"org.mongodb" %% "casbah" % "2.6.3"
)提前感谢
发布于 2014-07-04 15:08:35
我的沙龙版:
libraryDependencies ++= Seq(
"se.radley" %% "play-plugins-salat" % "1.4.0"
)代码示例:
dao.collection.aggregate(
MongoDBObject(
"$unwind" -> "$tag"
),
MongoDBObject(
"$group" -> MongoDBObject(
"_id" -> "$tags",
"count" -> MongoDBObject("$sum" -> 1)
)
),
MongoDBObject(
"$sort" -> MongoDBObject(
"$post" -> -1
)
),
MongoDBObject(
"$limit" -> 1
)
)https://stackoverflow.com/questions/18903848
复制相似问题