32

I'm currently trying to use MongoDB Compass to query my collection. However, I seem to be only able to filter the data.

Is there any way for me to sort the data as well? I would like to sort my data in ascending order using one of my data fields.

If MongoDB Compass isn't the best way to order a collection, what other GUI could I use?

cassiomolin
  • 124,154
  • 35
  • 280
  • 359
Aabhas
  • 363
  • 1
  • 4
  • 9
  • 1
    Hi, welcome to SO. Your question in it's current form is likely too general to get an answer. Show what you have tried and what is going wrong - see the link below for some details. Good luck, and happy hacking! https://stackoverflow.com/help/how-to-ask – kenny_k Jun 20 '17 at 13:47

1 Answers1

59

Using MongoDB Compass 1.7 or newer, you can sort (and project, skip, or limit) results by choosing the Documents tab and expanding the Options.

enter image description here

To sort in ascending order by a field myField, use { myField:1 }. Any of the usual cursor sort() options can be provided, including ordering results by multiple fields.

Note: options like sort and skip are not available in the default Schema tab because this view uses sampling to find a random set of documents, as opposed to the Documents view which displays a specific query result.

Stennie
  • 63,885
  • 14
  • 149
  • 175