[SERVER-45833] Sorting with collation that has `numericOrdering`, `alternate`, and `shifted` seems to ignore `numericOrdering` Created: 28/Jan/20  Updated: 27/Oct/23  Resolved: 07/Feb/20

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: 4.2.3
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Valeri Karpov Assignee: Katya Kamenieva
Resolution: Works as Designed Votes: 0
Labels: qexec-team
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Ubuntu 18.04 with XFCE


Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

Run the given script. I ran it using MongoDB server and shell 4.2.3-rc1

Participants:

 Description   

The below script prints that "950 000" before "970". I'd expect that the given collation makes MongoDB ignore whitespace and treat "950 000" as "950000"

db.dropDatabase();
 
db.createCollection('test', {
  collation: {
    locale: "en_US",
    numericOrdering: true,
    alternate: "shifted",
    maxVariable: "punct"
  }
});
 
db.test.insertMany([
  { price: '970' },
  { price: '950 000' }
]);
 
var res = db.test.find({}).collation({
  locale: "en_US",
  numericOrdering: true,
  alternate: "shifted",
  maxVariable: "space"
}).sort({ price: 1 }).toArray();
 
print(res[0].price); // 950 000
print(res[1].price); // 970



 Comments   
Comment by Katya Kamenieva [ 07/Feb/20 ]

Unfortunately, this use case is not supported by the ICU collation.
The behavior is matching the available demo tools:
http://demo.icu-project.org/icu-bin/collation.html
http://demo.icu-project.org/icu-bin/locexp?_=en_US&d_=en&x=col
http://www.unicode.org/reports/tr10/#Non-Goals : "Numeric formatting: numbers composed of a string of digits or other numerics will not necessarily sort in numerical order."

Comment by Carl Champain (Inactive) [ 29/Jan/20 ]

Hi val@karpov.io,

Thank you for the report.
I was able to successfully recreate the described behavior; I'm passing this ticket along to the appropriate team for further investigation. Updates will be posted on this ticket as they happen.

Kind regards,
Carl

Generated at Thu Feb 08 05:09:49 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.