Loading...
Loading...
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.
JIRAUSER1259703 commented on Fri, 13 Feb 2026 22:39:49 +0000: Sorry, missed the Operating System field: Linux
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" } ] }
MongoDB Integration
Learn more about where this data comes from
Bug Scrub Advisor
Streamline upgrades with automated vendor bug scrubs
BugZero Enterprise
Wish you caught this bug sooner? Get proactive today.