How To Connect MongoDB with Python | Creating MongoDB Atlas Cluster | Working With Pymongo #mongodb

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Applause] [Music] hello all welcome back to my YouTube channel so guys it's been long time we have created a video related to mongodb so if you see my mongodb playlist the last video was related to how can you create your mongodb Cloud cluster and how can you use it or else connect that particular cluster or instance to your local account or else to your local Compass so that was my last video so from today onwards we'll be using a program that is nothing but python we'll be taking Python and we'll be implementing or else we'll be using Python and with the help of python we are going to perform operations in your mongodb Cloud Atlas account I'm talking about the cloud this time you are not going to do anything locally so if your laptop configuration is not that high also it doesn't matter we'll be doing everything on the cloud so guys now let's not waste our time let's dive into our today's topic topic and discuss more about that before that if you have not subscribed the channel do subscribe the channel and on the Bell notification and also if you have any doubts related to this particular code whatever I'm explaining or if you have any doubts related to Career guidance related to data science or else data analysis how you are to do or else how what are the programming languages you require to learn and the key skills so if you want to know about that just comment below this particular video or else to any video whichever you are watching So based on your comments in the upcoming videos I will definitely answer the question so that it is not going to help only you but also to the others who might be having the same doubt so now let's not waste our time let's dive into the computer screen and discuss more about so guys you can see I'm using Google collab notebook for this particular video you can even see the name of the collab notebook this particular collab notebook link will be in this video description anyone can check it and run it and even they can use it so for this particular video right the main agenda will be that we'll be cre creating a mongodb account and we'll be creating a mongodb instance for free or else a cloud storage for free and we'll be using that and we'll be connecting that to our Google collab in which the python is internally working right so we'll be connecting it with python so this will be the main task of this particular video now let's start so the there will be only two things required for this particular video one is your Google collab notebook or your jupyter notebook or else your vs code anything of your choice there is no problem then a mongodb account so for this search for mongodb and open this click on sign in if you don't have account you have to create the account right so even I don't have the account so let me create the account continue with Google so let me use my my YouTube connected mail ID only so it's getting created I accept the Privacy policies okay submit so now successfully your mongodb account is created just in one click it is not going to take that much time welcome use your mongod account to deploy cloud storage yeah okay getting to know you so what is the primary goal to learn mongodb and how long have you been developing softwares in mongodb so it's your choice you can give anything randomly getting to know about the projects are mainly we'll be using python right so give python so it will be related to just give other or else give anything it's not an issue AML okay finish so guys you should get to know about mongod DB how can you connect it to python because mainly see you can see here let me continue this first I'll tell you why you require it so click on this m0 for free which is there you will get 512 MB storage of free and the cluster we can create it click on create it and now you can choose uh username of your choice and password so I'll just give it here Tech it's enough and password I'll just give it as so this particular account right I'll just terminate it after this particular video no one are allowed to use this particular account remember that so 1 2 3 or anything I'll just change the password or else after this particular video and then select the cloud environment and after this you will get the IP access list right so in this you can add the IP of your choice or else anything of your choice then create the user here you have to create the user this user is created now click on finish and close you can see here congratulations this is done so your cluster is created this is your mongodb cluster so I was telling you all right like why you require uh mongod DB normally when it comes to data science right or else uh when you are dealing with the data that huge data will be available in your mongod DB you have to pull it and you have to use it so if you want to access that you require python right machine learning operations and even deep learning operations whatever you will be performing you'll be performing with python right so for that you have to definitely connect to that particular cloud storage and you have to pull it right so for that you should know how to connect this particular mongod DB with your python first right so we'll be seeing how how we can connect that click on connect now when you click on connect here you will get option mongodb for vs code we can click this it's not an issue or else go back here you'll get an option for drivers yeah drivers go to drivers and in this select here Python and version Let it to be 3.2 it's not an issue so for this what we'll be doing now we'll be giving this right a full code so if you give your view the page full code if you give it you will get it directly or else you will get here only the URL which you can even use it later so it's not an issue uh this will be the URL so now mongodb account is created and we got the URL also our next task will be will will be going to our Google collab notebook or else uh jupter notebook now here the oper we need to do is we have to install a library called Pongo pip install Pongo so now just run this now it will start to install Pongo if it's already installed it will show you that the requirements is satisfied you can see it is installing now so guys you can see here the Pongo has been installed successfully now what we'll be doing we'll be importing this from import client so this is done so we'll be importing it once this is done right client is equals to so in our client what we'll be doing we'll be taking client and inside this we'll be pasting the URL of this particular database which we have created click on connect drivers python so let us just copy this and let's go here and let's paste it here and now here if you see the password whatever it is there right you have to change that and including that Arrow Mark you have to remove only the colon so after the colon what you have to do 1 2 3 4 5 I'm just giving my password I'll be changing the password after this video don't worry now this is done so if you run this it will be created now what we'll be doing we'll be using DB is equals to client DB is equals to client we'll be give it giving the database name as just DB DB will be the database name it's enough we don't need to give anything that much fancy also or else we can just give it as DB1 so this will be our database one and we need to create a collection also so for that what we'll be doing collection is equals to DB so we'll be randomly inserting any data for example YouTube will be my collection name this is just an example guys so normally what happens if there is a no database name with this particular name right in this particular uh cluster there is no database okay it's an empty cluster right now so when we run this line this particular database will be created and this particular collection also will be created if any of this is not there in that it will be created if any of this is already available it will automatically get connected to that one it is not going to throw any error okay you got it guys so now we have even created the cluster let us take any sample document name document is equals to we'll be inserting the data right see I already told you all in the previous video also J this mongodb right it will stores data in Json format so whatever program code you will be executing if you are going to insert any data it should be in Json format if it is in CSV format also it will be converted to Json or else you have to convert it name let us give as so this will be my first collection name and after this what I'll be giving City let us give randomly anything okay this is done so we have created a collection right now what we'll be doing we'll be inserting this inserted document let us take insert insert document is equals to we'll be creating a variable and inside this collection do insert insert one collection and that collection will be nothing but document so this particular document whatever we have created created here right we'll be inserting that into mongod using insert one method what is insert one what is insert many everything we'll be discussing in the upcoming videos and if you have watched my previous videos related to the local uh database right which we are working on shell same methods only it is not going to change so this is done right now what we'll be doing inserting the document is done and now we'll just print the message that it is inserted successfully or not print string do inserted document and ID is equals to ID of that particular document is nothing but insert doc dot inserted ID I want the inserted ID whether it's not inserted or it's inserted I should get to know right so for that again uh let us close it now client Dot close so once it is done we have to close the connection right so we'll be now running this we'll see now it's getting done let us wait and watch what it's going on so the connection whichever it is there we have created that so finally once everything the execution is done we are closing the connection also that's all nothing else here it's not going to be more complex it's taking more time failed what was the issue so guys actually I was checking like why I was getting this particular error so then I got to know that there was an issue with the IP address normally what happens when you are going to connect right you can connect it locally but your Google collab is cloud right so you can see that it is using only my IP address so I'll just give it I'll just delete that IP address I'll click on ADD IP address and I'll give it like allow access from anywhere when I give this you can see this will be the IP address or else access list entry so that you can access it from anywhere okay and I'll just confirm it when you click on this it will automatically enable that so whenever you are using the databases next time you can use it like allow access anywhere to get this right just when you are creating the cluster right I have deleted that particular cluster which I have created on the video because I forgot to add this one click on cloud and here you will get the option right to click on uh when you click on this cloud and when you click on this IP address right you'll get an option to add your IP address or else change the IP address in the network access you will get something called here as network access using which you can access it out or else you can directly search uh check here for network access this is the network access when you click on this network access you will immediately go to this particular option where click on ADD IP click on allow anyone to access and click on confirm so this is getting created now so now this is active now so but now if you run this I guess you will be able to easily connect right now not I guess definitely now we will be able to connect it out so let me just click on connect click on drivers python 3.2l or later and let me close this let me take this normal URL itself and now in my I'll again update this particular URL when it comes to password right when I was creating the new cluster I have even changed the password also same method right zero now let us run this and see I hope this should work right now yeah you can see here it's working right now if you see here inserted document this is the document unique ID let us go to our database and check it out click on browse collections now you can see here my database I have even changed the database name also and my collection I have created this both and you can see here whatever data I was having here it has been reflected here now if you want I'll change it to just SK change the city name to and let me just run this you can see it has been inserted successfully and now if I just refresh the document here itself you can see are two Collections and for each collection right there is an unique object ID you can see this particular object ID here only you can track it out so using this particular object ID only you can track any document whenever you require with the help of the object ID you don't need to search for that particular document every time so you understood till here guys so that's all for today's video just understand how to create the database and how to configure it you will be getting the issues like how I got so just go to network access page here and enable this add IP address and you should make sure that there was something here called allow from any way to access you have to enable that if you don't enable that it will not be allowed and even you can see here you can even create an IP address or else add an IP address and give it a limited time like for 6 hours or 7 hours after that that particular IP address will be removed automatically this is a great feature from mongodb so next we will be discussing how can we add the data into mongodb how can we read the data and how to perform aggregation and crud operations and everything so guys that's all for today's video do like share and subscribe thank you all
Info
Channel: SAI KUMAR REDDY
Views: 2,981
Rating: undefined out of 5
Keywords: mongodb tutorial, mongodb python, python tutorial, Pymong, google colab, google colab python, Python, MongoDB, Cloud, mongodb tutorial for beginners, mongodb, what is mongodb, Atlas, Cluster, data science, data analyst, data, data entry, career, free education, 2023 trends, education for free, coding for beginners, Coding for all, technology, technology gyan, sai kumar reddy, edtech, ai for data science, ai, subscribe, 2024, data science career, salary of a data scientist in india
Id: daMxiBS0odk
Channel Id: undefined
Length: 18min 48sec (1128 seconds)
Published: Mon Oct 09 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.