为什么 rank($rank) 不允许多个 sortBy 字段?

问题描述 投票:0回答:0

我在尝试根据分数和尝试对文档进行排名时遇到问题

"$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>
  },

是否可以根据多个字段对文档进行排名?

laravel mongodb laravel-8 ranking
© www.soinside.com 2019 - 2024. All rights reserved.