aggregate sort on string field inconsistent on Linux

    • Type: Bug
    • Resolution: Unresolved
    • Priority: Blocker - P1
    • None
    • Affects Version/s: 8.0.12, 8.2.5
    • Component/s: None
    • None
    • ALL
    • Hide

      I can provide the un-sanitized test data and actual pipeline if needed but data structure:

      {

          "_id": ObjectId,

          "subdocuments": [

               

      {              "_id": ObjectId,              "work_date": "YYYY-MM-DD",              "other values": "data"           }

             ]

      }

      Show
      I can provide the un-sanitized test data and actual pipeline if needed but data structure: {     "_id": ObjectId,     "subdocuments": [           {              "_id": ObjectId,              "work_date": "YYYY-MM-DD",              "other values": "data"           }        ] }
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Have the following (abbreviated) aggregate pipeline (go):

      ```

      bson.A{
              bson.M{
                  "$match": bson.M

      {                 "_id":         mydocumentid,             }

      ,
              },
              bson.M

      {             "$unwind": "$subdocuments",         }

      ,
              bson.M{
                  "$match": bson.M{
                      "subdocuments.work_date": bson.M

      {                     "$gte": startDate,                     "$lte": endDate,                 }

      ,
                  },
              },
              bson.M{
                  "$replaceRoot": bson.M

      {                 "newRoot": "$subdocuments",             }

      ,
              },
              bson.M{
                  "$sort": bson.M

      {                 "work_dates": 1,             }

      ,
              },
          }

      ```

      On Mongodb v7.0.29, this works as expected and I see the documents sorted as expected (wd is the work_date value):

      ```

      2026/02/13 15:06:24 wd: 2025-04-01 
      2026/02/13 15:06:24 wd: 2025-04-01 
      2026/02/13 15:06:24 wd: 2025-04-01
      2026/02/13 15:06:24 wd: 2025-04-01
      2026/02/13 15:06:24 wd: 2025-04-01 
      2026/02/13 15:06:24 wd: 2025-04-02 
      2026/02/13 15:06:24 wd: 2025-04-02  
      2026/02/13 15:06:24 wd: 2025-04-02  
      2026/02/13 15:06:24 wd: 2025-04-02  
      2026/02/13 15:06:24 wd: 2025-04-03  
      2026/02/13 15:06:24 wd: 2025-04-03  
      2026/02/13 15:06:24 wd: 2025-04-03  
      2026/02/13 15:06:24 wd: 2025-04-03  
      2026/02/13 15:06:24 wd: 2025-04-04 

      ...output cut here for brevity...

      ```

      However, on MongoDB v8+ on Linux, both bare metal and docker images, the following sort order is returned (wd is the work_date value):

      ```

      2026/02/13 15:06:29 wd: 2025-04-08  
      2026/02/13 15:06:29 wd: 2025-04-06 
      2026/02/13 15:06:29 wd: 2025-04-06  
      2026/02/13 15:06:29 wd: 2025-04-06  
      2026/02/13 15:06:29 wd: 2025-04-06  
      2026/02/13 15:06:29 wd: 2025-04-07 
      2026/02/13 15:06:29 wd: 2025-04-07  
      2026/02/13 15:06:29 wd: 2025-04-07 
      2026/02/13 15:06:29 wd: 2025-04-07  
      2026/02/13 15:06:29 wd: 2025-04-08  
      2026/02/13 15:06:29 wd: 2025-04-08  
      2026/02/13 15:06:29 wd: 2025-04-05  
      2026/02/13 15:06:29 wd: 2025-04-08  
      2026/02/13 15:06:29 wd: 2025-04-09 
      ```

      This was also reproducible with rancher-desktop on MacOS using both the official docker image and the mongodb docker image so it's not limited to one hardware system running Linux.

       

            Assignee:
            Unassigned
            Reporter:
            Mike Dotson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: