spring - 使用spring的MongoDB聚合查询
问题描述
db.getCollection('questionbank').aggregate([
{ "$group": {
"_id": {
"technology": "$technology",
"level":"$level",
"type":"$type"
},
"Count": { "$sum": 1 }
}},
{ "$group": {
"_id": "$_id.technology",
"QuestionCount": {
"$push": {
"level":"$_id.level",
"type":"$_id.type",
"count": "$Count"
},
}
}}
])
我正在尝试获得相同的输出结构。
谁能帮我在春天写下上面的查询。我尝试了很多但失败了。
解决方案
您可以使用以下 .
group("technology", "level", "type").count().as("count"), group("_id.technology") .push( new BasicDBObject("level", "$_id.level") .append("type", "$_id.type") .append("count", "$count")) .as("questionCount")
推荐阅读
- javascript - 显示数组中第一个值的函数,如果再次运行,显示数组的第二个值
- python - 如何在 Django 中获取过滤键和结果元组
- php - 如何在POST php中获取特殊字符'
- android - Android:清单合并失败
- spring-boot - 在 catalina.bat 文件中设置属性与在 setenv.bat 文件中设置属性有什么区别
- vue.js - 带有包含 document.write 的小部件 js 文件的 Vue.js
- javascript - Safari 浏览器 audio.play() 不工作
- python - 找出基于 HTTPS 的表单的 POST 参数
- reactjs - ReactJs 上的 PDF 视图
- python - Python3.x中调用Matlab .m文件后出现“TypeError”和“ValueError”如何解决?