Pip install pymongo dnspython
If you run this code, you might get an error saying that to use mongodb+srv you need to have dnspython installed. Mycol = mydb # this selects the collection from the multiple collections that might be in a database Mydb = client #this selects our database from our client which could have multiple databases if we wanted it to
#Pip install pymongo dnspython password
#change to your password and to the name of yoru database Then we connect to the mongoDB like this:Ĭlient = #connect to the mongodb using the url it gave us To use mongo db we need to import pymongo Step Two: Connecting to the database using pythonĪlright, the first thing we need to do in our python repl is connect to the database. Now we move to the actual programming part of it.
Now you should be able to see you document inside of your collection. Be sure to set it as an int64 and not a string. We’ll create a document (basically the same as a dictionary in python) with a key ‘burrito’ and a value of 0. I created a database called mydatabase and a collection called burrito
![pip install pymongo dnspython pip install pymongo dnspython](https://static.html.it/app/uploads/2021/03/1-mongo-python.png)
Click close and go back to the main screen. You’ll need this link to connect to your database. It will generate your a link that you can then copy
![pip install pymongo dnspython pip install pymongo dnspython](https://miro.medium.com/max/1400/1*Oj509-BGAzfDC3TSEkD6gg.png)
Select Connect you application, then select python as the platform and 3.6 as the version. It will take a few minutes for mongo to build your database, and then you should be looking at a screen that looks like this one: You should open up a screen that looks like this:Ĭlick the button to create a database userĬhoose the free version (free means you don’t have to pay any money)įill out a few details and then you should be good to go. You will then need to go to your email and confirm it, and sign in to your database. I know this is a repost but I accidently deleted it which was pretty stupid of me Step one: Make a mongoDB database (atlas)