[英]Remove a reference field from a mongodb document in a spring boot application
[英]List all documents from mongodb where the each document's one field has max value in spring boot
我有 mongodb 上的文件列表,例如
Id, name, surname, salary.
我希望所有包含max salary
的文件都會返回。 我知道我應該分兩步聚合查詢。
但我既不能配置它 JPA 也不能配置本機查詢方法。 我怎樣才能讓它發生?
[{
$group: {
_id: '$salary',
records: {
$push: '$$ROOT'
}
}
}, {
$sort: {
_id: -1
}
}, {
$limit: 1
}]
output 示例
{
"_id": 40,
"records": [
{
"_id": {
"$oid": "631b8ab07d8c3aa86bb1c5fc"
},
"name": "Bob",
"surname": "B",
"salary": 40
},
{
"_id": {
"$oid": "631b8ab07d8c3aa86bb1c5fd"
},
"name": "Alice",
"surname": "A",
"salary": 40
}
]
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.