MongoDB for Developers with Python Transcripts
Chapter: Deploying MongoDB in production (and playing it safe)
Lecture: Concept: Connecting to MongoDB via Python

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's review how we connected to our production server
0:03 from Python and Mongoengine, here's how we connected before,
0:07 we just said the alias is core and the name is dealership,
0:12 and that was it, we just let everything else be the default
0:15 and that worked fine when it was a wide open server on our local machine.
0:18 It didn't work so well for production,
0:23 so we saw that we actually added this function that
0:25 there is a whole bunch of different things here
0:28 so it takes the password, the port, the server, whether or not to use ssl,
0:31 the username, as well as the alias and db
0:34 and I kind of broke this into two different functions
0:37 that you can use for multiple connections in this example,
0:42 but you could jam it all into one like I did in the project.
0:45 So I created this dictionary and we set additional things
0:47 like the authentication source and mechanism
0:49 and to tell it to ignore the ssl certificate,
0:51 I put it in the dictionary so it's easy to print out
0:54 like in my log here is I am connecting to the database server
0:56 so you know which machine you're talking to,
0:59 how you're talking to it, what user you're talking as, things like that.
1:03 So if you want to just put all that data straight into register connection, fine,
1:06 you could do that but I find this to be valuable for sort of historical purposes,
1:10 so here's how we connected and in my real example I said
1:14 we're going to use the old version if you don't pass in
1:17 a user name of password, or other things,
1:19 but if you do then I'll switch to this more advanced version here.