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

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Speaking about queries, let's see how we could perform queries against our remote API.
0:07 Let's say that we want to find all the people where last name is Green. So we go over here to the URL and we set a query string
0:18 we use the where keyword and then we go with a Mongo syntax, you can see here it is basically a Json object
0:28 so find all the documents where last name is Green. Let's try this one, and as you can see, we only have one document back
0:38 and it is exactly what we were looking for, let's try something more complex and find all the documents where last name is Green
0:46 and also location.city is Ravena, which is my hometown in Italy. Zero documents back, and that makes sense,
1:05 it is what we expected, as you can see, the items array is empty. Now if we go back to my query and replace Ravena with New York
1:13 I should get back my Green guy again. Because location city is in fact New York, so as you can see, you can also query on subdocuments,
1:26 like we did here using the . syntax you can chain multiple conditions and you can basically use
1:33 all of the MongoDB supported operators like or, and, etc. You have also another option, if you don't like the Mongo syntax,
1:43 maybe you are not familiar with it, you can actually use the Python syntax, which is different, let's try one example where last name=green
1:58 same result, as you can see. So different syntax, similar result. Now we will see in the following segments that you can actually configure your API
2:17 and decide which syntax you want to support, by default, both of them are allowed, but you can actually turn Python syntax off
2:26 or Mongo syntax on and off, however you please.


Talk Python's Mastodon Michael Kennedy's Mastodon