MongoDB with Async Python Transcripts
Chapter: Document Databases
Lecture: Mongo Shell

Login or purchase this course to watch this video and the rest of the course contents.
0:00 In this chapter where we talk about the native tools and the native query syntax, we're going to use the Mongo shell for some of these examples.
0:10 So this is the mongosh or mongosh command that I had you install in the setup chapter.
0:17 Now in order to use it, we would just type mongosh or mongosh and it opens up.
0:24 If you type just by default, it's going to connect on localhost on the default port and all of those things.
0:29 You can also, of course, connect to remote servers with the right command line arguments. You would say, ""Use your database.
0:36 So you connect in this way, in this case, ""Use training. If you're not sure what the databases are called, you can always say, ""Show DBs,"" and
0:43 it'll list them out. Then you can say, ""Use one of them. And then you write queries about the data in there.
0:51 So ""Find"" is basically the ""Select"" type of statement. do, the way it works is you say DB, always always DB, this is directed at whatever the
1:01 active database that we set in the line above. And then you talk about the collections and
1:07 then find so we have a collections collection called courses. And then we want to find documents
1:13 inside the courses collection. So use this kind of dynamic programming style, db dot
1:17 courses dot find. And then what you pass defined is interesting, you pass a prototypical JSON
1:25 object. So in this case, we say we want to find the one where the ID underscore ID, the primary
1:30 key is 30. And you can see the result that we got back, obviously matches that. But if you pass
1:37 multiple things, we could say the ID is such and such. And it has, let's say, a display order of
1:45 five, that would be an and statement, there's ways to do ors as well. But the more pieces you put in
1:50 here the more specific that query becomes if you're not querying by the primary key.
1:56 We say the find, and normally you would get a, what would look like a minified result of JSON back, which is not the most amazing.
2:04 So if we throw this dot pretty on the end, we get this nice expanded good looking result set that is much easier on the eyes.


Talk Python's Mastodon Michael Kennedy's Mastodon