我在尝试根据分数和尝试对文档进行排名时遇到问题
"$rank must be specified with a top level sortBy expression with exactly one element"
查询是:
$resultListing = UserScore::raw(function ($collection){
return $collection->aggregate([
['$setWindowFields' => [
'sortBy' => [ 'score'=>-1, 'attempts'=>1],
'output' => [ 'scoreRank' => ['$rank'=>(object) [] ] ],
]]
]);
});
给出的语法是:
{
$setWindowFields: {
partitionBy: <expression>,
sortBy: {
<sort field 1>: <sort order>,
<sort field 2>: <sort order>,
...,
<sort field n>: <sort order>
},
是否可以根据多个字段对文档进行排名?