0

I want to sort data by name ASC, symbols and numbers are always come first, sorting field's type is string

I want it would be in different order:

  1. letters
  2. symbols
  3. numbers

example data as it returns now:

+rest day
/day
11 some
44
rest day
sport day

What i want is the alphabet order come first then follow by symbols and then numbers

Desired output

rest day
sport day
+rest day
/day
11 some
44
  • You can use regexFind and an aggregation pipeline, if you want to sort like this according to the first char: https://www.mongodb.com/docs/manual/reference/operator/aggregation/regexFind/ – nimrod serok Mar 30 '22 at 22:44
  • You can possibly use the Aggregation `$function` for a custom sort on the data. For example: [How to custom sort only specific results in Spring MongoDB?](https://stackoverflow.com/questions/66327889/how-to-custom-sort-only-specific-results-in-spring-mongodb/66338328#66338328). Note that the custom sorting is achieved using a JavaScript function.. – prasad_ Mar 31 '22 at 02:10

1 Answers1

0

Were you able to find the way in Mongo to sort in that specific order?

I've a weird sort order requirement

{ name: '> 1/2 blah'},    -- 1st Special Chars
{ name: '1/4 - 1/2 blah'},  -- 2nd Numbers
{ name: 'ABC ABC Blah Blah'}, -- 3rd Alphabets
NoisyBoy
  • 354
  • 3
  • 6