Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-31601

Ranking(using project) + sort + skip&limit(pagination) not working as expected

    • Type: Icon: Bug Bug
    • Resolution: Works as Designed
    • Priority: Icon: Critical - P2 Critical - P2
    • None
    • Affects Version/s: None
    • Component/s: None

      When I perform a sort using a project fields value like this:

      [{
        '$project': {
          'metaData': {
            '$let': {
              'vars': {
                'array': []
              },
              'in': {
                'sizeArray': {
                  '$size': '$$array'
                }
              }
            }
          }
        }
      }, {
        "$sort": {
          "metaData.sizeArray": 1
        }
      }].
      

      Here I perform a sort using the size of the array. In this example the size of the array is zero, but it can vary if the array is made out of value of a field in the collection.
      Everything works fine until now. But if I perform $skip then $limit after this many documents are repeated when the value of $skip changes. For example:

      db.getCollection('venues').aggregate([{
        '$project': {
          'metaData': {
            '$let': {
              'vars': {
                'array': []
              },
              'in': {
                'sizeArray': {
                  '$size': '$$array'
                }
              }
            }
          }
        }
      }, {
        "$sort": {
          "metaData.sizeArray": 1
        }
      }, {
        "$skip": 4
      }, {
        "$limit": 4
      }]);
      

      When the value of skip goes from 4..8..12, many documents are repeated.

            Assignee:
            mark.agarunov Mark Agarunov
            Reporter:
            tanmayawasekar Tanmay Awasekar
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: