Sort mongo results by enum string value
Is there a way to sort documents from MongoDB based on enumerating string values?
What I'm trying to achieve is just sorting the log message objects based on severity. So the docs look like this:
{message: 'An error', severity: 'error'}
{message: 'A warning', severity: 'warning'}
{message: 'Informational message', severity: 'info'}
And I would like the results to be sorted by logical severity (e.g. error-> warning-> info) rather than alphabetically.
+3
source to share