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

Decreasing order sort on clustered collections on replica sets returns increasing order

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.3.0-rc0, 6.0.5
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • Fully Compatible
    • v6.2, v6.0
    • QE 2023-02-06

      There was replica set passthrough tests that were failing on mongosync for clustered collections so they had previously been disabled. In trying to re-enable them (REP-1479), I found that there seems to be an issue with sorting and clustered collections on replica sets on v6.0.

      The example I am about to add is with a clustered collection with collation, but I think the issue is present on other types of clustered collections as well.

      // Create the collection
      const defaultCollation = {     locale: "en",     strength: 2 };
      db.createCollection("clustered_collection_with_collation", {clusteredIndex: {key: {_id: 1}, unique: true}, collation: defaultCollation})
       
      // Insert some documents
      db.clustered_collection_with_collation.insertOne({"_id": -5})
      db.clustered_collection_with_collation.insertOne({"_id": 0})
      db.clustered_collection_with_collation.insertOne({"_id": 5})
       
      // Should sort documents in increasing order, sorts correctly
      db.runCommand({
      	"aggregate": "clustered_collection_with_collation",
      	"pipeline": [
      		{"$sort": {"_id": 1}},
      		{"$project": {"_id": 1}}
      	],
      	"readConcern": {"level": "majority", "afterClusterTime": Timestamp(0, 1)},
      	"hint": {"_id": 1},
      	"cursor": {},
      })
       
      // Should sort documents in decreasing order, actually sorts in increasing order
      db.runCommand({
      	"aggregate": "clustered_collection_with_collation",
      	"pipeline": [
      		{"$sort": {"_id": -1}},
      		{"$project": {"_id": 1}}
      	],
      	"readConcern": {"level": "majority", "afterClusterTime": Timestamp(0, 1)},
      	"hint": {"_id": 1},
      	"cursor": {},
      })
      

      As we can see, when it tries to sort the documents in a clustered collection in decreasing order, it still sorts them in increasing order.

            Assignee:
            alyssa.clark@mongodb.com Alyssa Clark
            Reporter:
            rohan.sharan@mongodb.com Rohan Sharan
            Votes:
            0 Vote for this issue
            Watchers:
            15 Start watching this issue

              Created:
              Updated:
              Resolved: