MongoDB for Developers with Python Transcripts
Chapter: Course conclusion
Lecture: Lightning review: Shell query syntax

Login or purchase this course to watch this video and the rest of the course contents.
0:01 The MongoDB shell and native query syntax; we saw that the MongoDB shell which you start by typing the word 'mongo'
0:08 and it just runs the shell, tries to talk to the local one, there's all the different ways to get it to connect to different servers as we've seen.
0:14 So once it starts you get this little greater than prompt and you write Javascript so we interact with MongoDB at the lowest level
0:23 in Javascript in a textual way and actually this is converted to bson a binary extended version of json.
0:30 So here we type something like db so this is the database we have active and book would be the collection name
0:36 or table if you're still thinking relationally, but the collection name, and we say things like find or count or sort, or things like this
0:43 and what we give it is this prototypical json object and what we get back are all the things that match the elements of that prototype.
0:51 So here you can see we got two records back and they both had the same title as the title we indicated here.
0:57 So it's very much about passing these prototypical json documents, however sometimes we have to do more than just say
1:05 I want basically equality in my search, I would like to express things like greater than. So this query here that we have written
1:13 is actually doing a couple of very interesting things, maybe the thing that stands out the most is this greater than operator,
1:18 so the dollar gte is indicating, the dollar indicates an operator, and gte is the name the greater than or equal to operator,
1:24 so instead of just saying ratings.value is nine, we're saying I'd like all the ratings where the value is either equal to or greater than nine.
1:31 The other powerful and interesting thing here is we're actually traversing this hierarchy of the document
1:37 we're going to find the ratings array which is a list of subdocuments which has a value as an integer,
1:42 so we're actually reaching down inside that document and we're doing this query with this operator.

Talk Python's Mastodon Michael Kennedy's Mastodon