我正在使用mongoose来处理我的数据。到目前为止,我在这里得到了这个
const personal = await culvertSchema.aggregate([
{ $match: { "characters.name": selectedCharacter } },
{ $unwind: "$characters" },
{ $sort: { "characters.scores.score": -1 } },
{ $limit: 1 },
]);
但它似乎并不适用于对“分数”进行排序。或者我甚至没有正确地访问它们。我不确定.我怎样才能对给定角色名的分数进行排序?
这是我的结构:
{
"_id": "336277029060345856",
"characters": [
{
"name": "druu",
"scores": [
{
"date": "09/03/23",
"score": 41
},
{
"date": "09/03/23",
"score": 12
},
{
"date": "09/03/23",
"score": 52
},
{
"date": "09/03/23",
"score": 100
}
]
},
{
"name": "druuwu",
"scores": []
}
]
}
谢谢你,谢谢
1条答案
按热度按时间vq8itlhq1#
在当前
$unwind
之后执行$sortArray
Mongo Playground