Details
Description
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.
Attachments
Issue Links
- is depended on by
-
SERVER-73423 CLUSTERED_IXSCAN with sort generates two duplicate plans
-
- Closed
-
- is related to
-
SERVER-73482 $natural hint overrides sort on clustered collections
-
- Closed
-