How does mongodb sort numeric values of type string?
There is no direct way to help you do this, but there are some flexible ways. For example, save its value into two fields, one number and one string. I will not elaborate on the specific measures, because basically this is a wrong idea, although it can be done, it is very inefficient.
Because you areThis problemI know what you need is actually a “fuzzy search” of numbers, but I don’t know what you mean by “fuzzy search” and how fuzzy it is. Because “fuzzy search” for a value is a rather strange requirement, which means that what you need may not be a value at all. However, it is also proposed here to sort the field numerically. In my opinion, these are two contradictory requirements. Without explaining the business scenario, I can’t judge what the correct type should be, and I can’t tell you what to do.
Basically, my personal principle is: a field should be of whatever type it is and should be stored as it is. Don’t cause new problems for solving a problem, it will only make the problem more complicated. Let’s find out the essence of the problem before finding a solution.