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

Query result not correctly sorted when using unwind and facet with concurrently inserts

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

      Query result are not correctly sorted when using unwind and facet when items are inserted concurrently

       

       .aggregate(   [   {"$match": {"_id": feed_id}},   {   "$lookup": {   "from": "items",   "localField": "_id",   "foreignField": "feed_id",   "as": "items",   }   },   {"$unwind": "$items"},   {   "$sort": {   "_id": 1,   },   },   {   "$facet": {   "result": [   {"$replaceRoot": {"newRoot": "$items"}},   {"$skip": offset},   {"$limit": limit},   ],   "total": [   {"$count": "count"},   ],   },   },   ],   ) 

      This result on a random order instead of ordering by items._id

      If inserts are done sequentially, results are as expected

      Environment:

      Any MongoDB version

       

            Assignee:
            backlog-query-execution [DO NOT USE] Backlog - Query Execution
            Reporter:
            mmicael@gmail.com Micael Malta
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: