Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: What is Eve?
Lecture: Exploring Eve: Sorting

Login or purchase this course to watch this video and the rest of the course contents.
0:00 And what about sorting? Of course you can sort too,
0:03 you just have to use the sort keyword in your query definition,
0:06 so for example, here we are sorting by location.city and then by last name,
0:13 and because I am using a dash before the last name,
0:17 field I want then reversed.
0:21 So basically I am looking for all the people with no filter,
0:25 because I am not using the sorted by location.city
0:29 and last name reversed.
0:32 Let's see what happens, we have 7 documents,
0:35 the first document here has no location subdocument as you can see
0:40 the second is the same, no location,
0:43 the third one is in Ashfield
0:50 and then we have another person living in Auburne,
0:56 and then New York comes, and then San Francisco,
1:00 San Francisco again and if we check it on the last names,
1:03 we will see that they are sorted by diverse order.
1:06 For example, we have 2 people living in San Francisco
1:10 let's go and see, we have miss Julia Red first
1:14 and then comes Miss Serena Love,
1:18 so yes, we are getting them in reverse order,
1:21 of course, we can also mix a filter with sorting,
1:24 so here we might go with something like where—
1:38 okay, so here we are looking for all the people living in San Francisco
1:43 sorted by last name reversed.
1:49 Only 2 documents, and we can see they both live in San Francisco
1:56 and the first one has last name Red
2:01 and then Love, again, if I remove the dash here
2:05 I am sorting by last name
2:08 and we should get the same two documents
2:10 but the first one is Love this time and the second is Red.
2:17 Also, when using sort you might want to switch to a Mongo syntax
2:22 something like this, which isn't probably very intuitive,
2:29 but you can do that if you want to,
2:39 same result, of course.