Eve: Building RESTful APIs with MongoDB and Flask Transcripts
Chapter: Appendix: Deploying MongoDB
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 from Python and Mongoengine, here's how we connected before,
0:08 we just said the alias is core and the name is dealership, and that was it, we just let everything else be the default
0:16 and that worked fine when it was a wide open server on our local machine. It didn't work so well for production,
0:24 so we saw that we actually added this function that there is a whole bunch of different things here
0:29 so it takes the password, the port, the server, whether or not to use ssl, the username, as well as the alias and db
0:35 and I kind of broke this into two different functions that you can use for multiple connections in this example,
0:43 but you could jam it all into one like I did in the project. So I created this dictionary and we set additional things
0:48 like the authentication source and mechanism and to tell it to ignore the ssl certificate, I put it in the dictionary so it's easy to print out
0:55 like in my log here is I am connecting to the database server so you know which machine you're talking to,
1:00 how you're talking to it, what user you're talking as, things like that.
1:04 So if you want to just put all that data straight into register connection, fine,
1:07 you could do that but I find this to be valuable for sort of historical purposes, so here's how we connected and in my real example I said
1:15 we're going to use the old version if you don't pass in a user name of password, or other things,
1:20 but if you do then I'll switch to this more advanced version here.


Talk Python's Mastodon Michael Kennedy's Mastodon