Mongo DB Using Python Programming | Document-oriented NOSQL Database

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] so welcome guys uh today our concept is mongodb and python drivers which we are going to use it in the mongodb to connect and what is the reasons to use the nosql database mongodb is one of the type of nosql database what is the reason there are three reasons storing the large volumes of the data without structure that is one reason and second reason is using the cloud computing and storage okay if you want to store the large data into the cloud services we can use this a lot so main important thing is no structure when you are using the mongodb there is no structure here and it doesn't mean like we are we are not using any tables or something like that so we are not going to use such type of data here it's completely different and most important point here rapid development if you are developing using the modern agile methodologies a relational database will slow you down because i have to follow the lot of relationship between the tables and a lot of things is there so a nosql database does not require the level of preparation typically needed for the relational databases okay next thing is what is mongodb so mongodb is a class or it is basically a cross-platform document or into no nosql database in single sentence okay which is written in c plus place okay it is an open source document database that provides very high performance and automatic scaling and simple words we can say that mongodb is a documented oriented database okay and uh and we'll we'll see the next slide who behind this software who behind who which companies actually developed this software if you can ask me so was developed by a new york-based organization named called tengen odb is available under the general public license for free and it is also available under the commercial license from the manufacturer and one more important thing is the mongodb right now the company name is the mongodb previously it was the engine now the name is got changed the first ready production of the mongodb was released in march 20 2010 okay but in 2019 the company shifted to a open source initially it is it is developed as a software then later they move to this one is the open source development model first ready production has been considered from the version 1.4 so you can think about this we are in the 2021 and 10 years back only this this software came this mongodb came into the software basically okay so first production went live on the on date of march 2010 okay the purpose of building this mongodb is very simple what was the need of mongodb why we are building its answer is very simple all the modern applications required the big data fast features development and flexible deployment and there is a older databases systems are not complete enough and mongodb was needed at the time when we are talking about the big big data era right so main purpose of this mongodb building there are so many features are there so let's talk about the features one of the future is load balancing and as i said like we can use this mongodb in the cluster environments there is a multiple servers we can deploy this mongodb on the multiple servers just looking at once we can use it in one server you can use it multiple servers and one more important thing is it supports the master slave replication and and the next feature is scaling from the single server deployment to the large complex multi multi site architecture we can use this mongodb for the small applications and also for the launch big data applications as well right and uh also one of the great feature is uh it supports queries and also we can use this one is for the a schema less database it is not having any schema like tables relationship there is no such concept here okay and uh if you ask me what is the adap virus means so basically uh in mongodb you can search by field and you can use the query and it is also supports the regular expressions the adapt virus means uh it is not just you can use only normal queries generally we know that select star from the table table here we can search by field by range query and also it supports the regular expressions we can write regular expressions to get the data from the uh database and schema less there is no tables here easy to maintain in the case of values because i will tell you what is happening so why this statement is easy to maintain in the case of failures in the sense we are maintaining this data as a duplicate as i told you you have the one big cluster in the cluster there are multiple servers we are going to store information into the each server it provides high performance and also stores the files of any size easily without complicating your task okay and the main accomplishment of this database is because it is completely written in the c plus place okay and come to the point here additions so this software is available in three editions this is what you should know okay the first one is the community server which you can download in your local computer you can work work on it this is for the uh developers edition and the people who are the developers they can use this community server and also there is enterprise servers all companies use this one clients and big big companies because enterprise server is little different from the community server all the complete features of the software is available in the enterprise server and the last one is atlas so i can say it is a cloud server okay this atlas is the mongodb cloud database okay so community server which is for the developers enterprise server is for the uh it's like a physical database uh without using the cloud and the last one is atlas we can say it is a cloud server community server enterprise server and cloud server today we are going to use the community server how to download how to configure in our local and what are the things and all we are going to look into it okay so look at that last year 2020 and december 22nd uh the latest uh release patch okay so this is a 4.4.3 so we can so moving to then where mongodb used this is the question right we have the mysql oracle podcast sequel circular trees microsoft sql server there are so many databases are there but those are all relational databases but where i can use this mongodb in my projects are like where exactly this is needed the first thing is we can use it in the content management and delivery when you have the lots of lots of lots of data like huge data so much of content is there how to manage that content how to deliver that content how to integrate that content with other services all these things which basically comes through here and basically mongodb deals with the big and complex data and there is no relationships guys when i'm talking about mongodb no relations here okay and also user data management and if you take any e-commerce applications there is so many users are there in the e-commerce right if you take amazon the user database its user data itself is a separate database they will maintain okay even if you take facebook or different websites the large companies websites they will maintain the data separately that maintain the separated database for the user data so something is like this user data management and the last one is the mobile and social infrastructure so for this one also we can use this mongodb these are the four uh the common things which i mentioned but we can use it in many places so mongodb deals with the huge data big data something like that okay and what are the operating system is supported odb supports almost all operating systems windows vista unlater because mongodb does not supports the windows xp of course nowadays no we are not using the windows xp osx it is nothing but mac os and also we can run this mongodb in the linux and also we can use mongodb in the solaris so these are the four types of four various operating systems we can use only thing you should remember is mongodb does not supports windows xp okay so moving to the next slide so this is important here look at this tools there are so many tools but very important tools i mentioned here in this slide the first one is the mongodb compass so in our previous discussion on postgres sql as i i told you that there is a gui that's called user interface tool name is called the pg admin for mysql so mysql workbench is the gui something like this for oracle it is sql developer right for sql server microsoft sql server that is sql management studio like that so tools basically like mongodb compass uh is one of the uh tool which we can use for the gui to see all the documents collections i will show you in shortly and mongodb shell if you want to execute uh the data to see that data in your system unlike if you want to insert the document if you want to create a collections and all these things we can use the shell also shell is nothing but a command line interface we can use the command line interface we can use the gui and also there is something called mongodb charts this is for the visible representations so if even if anyone is aiming for the data visualizations like generally we use the uh the matplotlib and the c-bone there is so many python packages are there and also we can use the microsoft business intelligence tool tab blue there are so many tools are there okay in similar way if we want to visualize the large volume of the data through mongodb we can use this mongodb charts okay and it is not only these three tools there are many tools but i just consider these three are very important as part of the data science and ai and if you are very familiar with using the gui we can go for compass and if you are good at the command lines write in the commands and all db shell and if you are working on something why usable representation is very important see if it is one million records at least i can show on the screen but what if i have the 30 million records 45 millions of records it is difficult to visualize that data so especially when you're using the mongodb we can use these charts there is a separate tool for this okay so moving to the next one what is the mongodb atlas right let me tell you so mongodb atlas means it is a fully managed cloud database as i told you at the beginning there is a three types or three editions are there okay one is the community edition that is the developers use the next one is the cloud edition and one more edition is also there that's called the enterprise edition now i am talking about the cloud edition job what is mongodb at last it is a fully managed cloud database you can see this at last in the uh aws microsoft azure and google cloud so all these are the big cloud services we can get this at last and this atlas service is available in the amazon web this atlas service is available in the amazon web services and microsoft azure and google because these are the three big companies amazon microsoft and google the service available there because why i'm telling uh if you are going to host your pro ai model or any any other application in the generally we host in the aws write cloud but this is a this is the better way we can use mongodb directly okay so mongodb is the open source one and we can and this atlas stores to secure data because when you say that cloud environment the first concerns comes how far it is secure when i am going to host my data on the public cloud remember guys aws azure google cloud these are the public clouds these are not the private clouds okay so you are sharing these resources with others ip addresses and also how far it is uh secured with the data so yes the secure for the sensitive data are for example you are storing any tax id uh or like if you are storing anything like other number or you are storing something related to the your password or anything which is sensitive data which is more secure and most important thing this mongodb atlas we can use on the cloud clusters not only one cluster multiple clusters also we can use because we can use it as a big applications on the cloud so moving to the next one what is the mongodb ops manager right so what is the mongodb ops manager previously such previous slide i explained about uh the public cloud this is the private cloud previous one was like a class this is ops manager if you want to use mongodb services on private cloud then ops manager is the tool okay so this is mainly for the private cloud on-premises management platform only like within the company we can use this service because most of the companies thinks most of the clients thinks hey if i'm going to put my data on the public cloud what is the security still even though you say number of things to the client client thinks about the security so even mongodb come up with the solution for that question saying that they have the mongodb ops manager we can use this service on the private cloud which is on-premises management platform okay and it's runs and manage mongodb seamlessly with the kubernetes okay we can use this uh mark kubernetes to run this ops manager but this is something like infrastructure level if we can talk about this ops manager okay and it has so much of backup management and in-time recovery yes this is important right and also it supports the multi-cloud clusters within the organizations within the client products generally we use that way okay moving to next one what is the main differences between the rtb ms so i'm missing your spelling call rdbms so we can say that it is a normal sql database and nosql databases but in this example so in this example i am explaining that what is the differences between the a relational databases and especially this mongodb so if you if so what is the difference is generally if you go to the relational databases we have one-to-one relationship there is and many-to-many relationship many to one relationship that's where we use the foreign keys and we have the joints we joins the two tables by using the inner join outer join left outer join and all but if you look at the mongodb we don't have such concepts here we don't have so mongodb is a schema less database so basically we store the document here so there are maybe difference between the number of fields contained and size of the document from the each document but structure of the single object is clear in the mongodb there is there are no complex joints in mongodb mongodb provides the facility of deep query because it supports the powerful dynamic query on the documents and it is very easy to scale let's let's see the table here this table will give you the more information guys okay against so table is there in the rdbms but this is just a citation which i am giving that you can refer in your mind don't uh think like okay this is exactly the same but i am just giving the citation here the table is there in the normal sql databases but if it comes to the mongodb it is a collection right and rdbms there is a row table has the rows and columns but if you look at here this is a json document there is a collection inside the collection there are the documents we can write one document two document three document four document and number of documents we can write but these documents are in the structure of json okay and i also mentioned in the bracket called the beason it is called the binary json i will talk about that what is the binary json and we will have a look into it so okay example i will say that in sql databases if you want to store the images video how we are going to do it guys we are going to use the data types names called the clock block and something like this but in mongodb okay text you can store with the json format what about image what about video okay that's the question we need to think so that's where this basin comes into the picture not exactly the same but i will explain you how we can store the multimedia content in the mongodb and index is index only join is embedding and linking and partition is shut okay so next one installation how to install this mongodb right uh i will show you so it's mainly i'm going to use this windows mac linux but currently i'm using the mac but i will it is easy to install no need of following any any documentation you follow only mongodb documentation they are given the very clear steps and more important thing we can going to discuss about installation part in shortly but i'm finishing the content first okay so developing with mongodb so it's not just only with the python there are so many tools and so many drivers are available like you are seeing the c and c plus plus c sharp node.js java go language php python shift scalar rest ruby so all these not only these languages we can also use many more languages to connect with the mongodb so this the diagram are like you can see the the picture you are seeing on my screen actually i copied from the mongodb option website itself okay so it supports all these databases all these programming languages guys but we have to go and bring the drivers but let's see this next question how to use uh how to use a mongodb when you are writing a python program how to use this one okay so very simple there are some libraries are there we are going to use uh we are going to experience with the coding how we can connect with mongodb using the python programming that is also i'm going to tell you in shortly and what are the python drivers for the mongodb right if you see that uh we we have our drivers for the mysql and also we have drivers for the postgres oracle similar way mongodb also having the driver is called the pi okay which is recommended by the mongodb itself nobody else directly mongodb itself they're saying that go and use this pi for your application development okay it is a mostly used library and mongodb itself is recommending this one and for example if you have any asynchronous calls uh if you are dealing with your application motor motor is also one type of python driver which we can use it for the asynchronous mongodb server applications these are the two drivers we can use to develop the but in our session basically we are going to use the pi okay so let's how to install this pi in your local computer it's very simple uh you can use the pip installation and pie mango and easy install by so two ways we can install this so pip install and easy install and open the actual website of mongodb is a fully management database okay and this is mostly used i also talked about charts it is the native utilization of the mongodb data and also software is available as the community edition enterprise server and also there is some developer tools compasses for the gui mongodb we can download and also we have the connectors and also it is i don't want to talk about the premise prices pricing is only for the cloud services and on-premises services and mobile services there are something is there okay so this you can have a look into it but if you are using the cloud one okay and uh if you want to learn these mongodb and there is a blog university and there are so many videos is also available here in this university it is a free online courses from the mongodb itself if you want to be more ideas see there are so many courses out there you can go and complete these courses if you are interested these are all like well designed and very nice tutorials and from there even there is a mongodb youtube channel you can go on follow them there is a good and you will get the cert if you want to achieve the certifications there is a various program developer certification is the dba that's called database administrator certification is also there okay you can find this information from their website um because i don't want to go in detail and the main thing here uh documentation solutions is okay the main i'm going to talk about the docs so we can cloud is there server is there driver and a lot of things are there but let's talk about the server main thing is the server database right so before going to look at this documentation we need to download the this software so just go and click on this software and that there is a community server and just click on this community server and you can download here okay so basically you are downloading the mongodb community server and it is available with the various versions and don't go for the rc0 just you can use any one of these any one of the versions by default it is pointing to the 4.4.3 this is also fine you can download the latest one but you need to select which operating system you use but there are so many things he has mentioned here but if you are the windows operating system you'll get the file name is msi so better you can go for the msi file or like g5 it is up to you and click the download you'll get the download button okay and also there is a different tools all there but that's up to you if you want to download it and download but uh as part of this you can download this community server and also you can download something called compass this compass is like gui okay so it is a graphical user interface so you can you can download this one also here so you can click on download it will be downloaded so both the things you can try to download it and installations and everything is easy for example if you want to know the installation steps you can directly go to their documentation and click on the installation and you basically installing the mongodb community edition and you just click on this and go to the windows because most of the people use the windows operating system and once you downloaded this and they are clearly mentioned the steps guys no need of asking anyone okay first you download the dot msi installer in your local and after that run that installer and uh you will get the screen like this screenshot also they are given we can select this one run service as a network service user so you need to follow these steps don't uh you just follow these steps simply you read this one follow it okay this is how it works guys and also when you are downloading itself there is an optional to there is a wizard will come here mongodb compos it is a user interface you can also download this one by default it will download so if you don't want to download both at a time then you can also separately download the mongodb uh this one compass compass is like ui so you can download it so that's that's something you have to do it with the steps so once you did the installation and uh you can see that to begin c this is what start mongodb community edition as a windows service if you want to start this service i have to use this uh this command so how to use this one so first you need to do something after you're done with the installation go to this folder okay so go to this folder they are saying like this so you can install and configure the mongodb as a windows service during the install the mongodb service started up on the successful installation so you have to go to these folders and you can click on this mongodb mongo.exe file so it will be it will be there in the program files mongodb server and which version you are using bin folder dot exe okay so this is what so you can open this one you can write shell programming you can write execute this uh you can also create databases and all but don't do it anything so you can just follow these commands are very easy to do it but i am since i'm using the mac i am going with the mac here if you look at this this is a similar code you can install it and do it but to run the service servers here you can just copy this service the brew services start mongodb i'll go to the terminal terminal here is nothing but so which is like command prompt we can refer into the okay same thing you can write for in windows system okay so i'm just enter this one brew services start uh okay there is already a is running in my system it's already started but again you can see here it is saying that mongodb community because already i started the mongodb iphone community at 4.4 because i am also using the 4.4 so if you can go back to this one if you want to stop the server we can use this brew services stop mongodb community for we can stop the server as well okay if you want to know what are the databases okay if you want to know the mac voice services in my system so you can run this command we can see the list of databases are there in my local computer so i have the cassandra i have the mariadb i have the mongodb community i have the mysql and postgresql which is stop the rest are all is started and running at the background right so these are the various databases is there in my local this is nothing but the process name process list process which user is there all the information is there okay so as simple as this uh all the comments is there that's where it is there and if you want to connect to the shell okay we can say that enter so when you say enter you are connecting to the shell shell is nothing but a command prompt interface for the database if you want to get the data if you want to see the data and all we can use it here for example as i told you earlier once you connected this one if you want to see the databases you can enter the gbs so you can see all the list of the databases here show dbs okay so first time these comments may be little uh i mean you are looking at this but you can see this all the databases will be there but maybe i am using the auto mobile is my personal one sem is also there e-commerce is also restaurant will be by default will be there in your computer so by default local will be there okay this local will be there by default but you can create multiple dbs here so already i installed the compass in my local i'm going to open the compass mongodb compass so let it be open you can see the same dbs even in the graphical user interface okay you can also see the same thing in the graphical user interface i'm just opening up this let it take time no problem so okay more important thing you should know here what is the default port number for the the default port number for the is 27017 and if you want to connect this one just click on the connect it will connect and will show you the all the databases so whatever your sorry whatever you are looking at on the same database list you can from the your shell these are the databases same database as you can see so in the sense if you are not good at the writing the commands okay and better you can go for use using this uh this databases so this is the database name and there is a what storage what collections are there what are the indexes and all right so something like this we have it now i will go one more step ahead and we'll show you this but before going to that we need to understand the what are the mongodb data types okay so what are the mongodb data types so generally if you if you look at the sql databases we have the uh var care and int there is a text something like this is there right but if it comes to the mongodb data type there is a string integer boolean double uh min and max keys arrays object null symbol and date all these things are there and if you want to look at those information it's very simple guys one of the best documentation is this one only okay this mongodb documentation only and uh let me show you that also to you okay and this is a documentation cloud operations click on this shell and how to configure the shell in your local basically you don't need to configure the shell in your local by default it will be installed in your local computer and also like see your installation is there we can basically shell is different for the community edition enterprise edition you always okay this mongodb you always think into the three editions okay i already explained in one slide here in in today so there is a linux edit so there is a community edition enterprise edition is that most of these two things you need to focus another one is the cloud edition anyway cloud is not required here okay so look at this install on windows they already by default will be installed in when you are installing this one but if you want to specifically install this one just go ahead and install in your computer also so if you select this one by default will be shell will be there in your local no need of any separate one and you can open your command prompt uh then you can automatically uh you can you can click on this dot exe from this file this will be created so this is how this will be there if anybody is facing any issues you can ask me and then i will help you okay if you are able if you are not able to connect with mongodb okay unfortunately i don't have the windows otherwise i would have shown you that uh that also yeah so let's back let's back to this programming here these are the databases which i can see with the show dbs and all right now i want to create my own database here so if you want to create for example use i can say that um okay so ds ai are like ds data dst so i'm creating dst data science team and if you click this so it is switch it to the ds team and automatically switches but it is not created basically right the ds team is not there but it is automatically creating and checking that if you want to see that current database which you connected to that that is a db okay so what is the current database you connected to the ds team but i want to see that database list again enter show dbs do you see that name here guys do you see that name here automobile sem admin bank company config e-commerce is there but you are not seeing it so i'm going to switch it to the e-commerce okay okay i switch it to the e-commerce now i'm going to show that show the beast and you you see something we created the uh what we created here dsteam do you see the ds team even though i switch it to that no you want to know the what is the current db you are pointing to the e-commerce but where is my db anybody guess i created the db name called what is that what is the name of the db db dst data science team but it is not showing immediately because because there is no data at least if you create one document then we can see this this can show to you since there is no single document in your mongodb newly created database name called dsteam that is the reason it is not showing it so you have to create uh some data here okay so what i'm going to do right let me connect to to the the name called dst so i'm just connecting to this so what i'm going to do right i'm going to insert some one document insert at least one document okay so i'm going to use the name called db dot and since i am already inside this ds team so i'm using the db dot and command name is called insert dot okay we can use insert or like you can specify the name of the uh document name what is the document name i can say that skill skill is the document name and the insert so in insert and i will take this is the function so inside that okay we are going to enter the some information so document is in the form of the document is actually there in the json format okay json means keys and values so for example we can say name is name and colon and we can mention some name okay for example you can okay so here it is the ai so i am just closing this one double quotes curl braces called close and close this one also this is nothing but a json object uh just in document you are creating it here i'm just going to enter it is saying that inserted the one okay now you can go and look at this show dbs and you will see something is uh ds team now previously there is no dst even you can go back to the mongodb compass and you can refresh this button and also you can see something called dst which is created here there is no commit there is no rollback here it is not like sql and skill is there here if you can go and click the skill and you see something called underscore id so for every document there is id will be created this is a how many digits guys 16 visits now there is an assignment to you okay you have to understand what is the underscore id in the database documentations so on what basis it is created is there any formula for this and you just study it and i will anyway update you if you want to change this information also from front end we can change so we can say that this is the ai program so i'm changing it this ai programming click on update button and i will go back sorry i will go back to this and i not i want to see this collection see if i go and use the db i'm connected to the dst so whatever the document which i created i want to see so how to see that document guys any any idea okay anyone to how to query the documents so we need to use the name called db dot and we can use the name called uh so whatever the name you use the basically we can say that the name here is a scale and dot find okay find is the function we are going to get it if i go and enter it is giving the information to me what document you inserted there and one more important point you should remember here the skill is nothing but the collection okay so let me tell you story here so let me go back to the uh this user interface see ds team is the database remember this terminology ds team is the database inside the database i have the skill the skill is nothing but a collection in the collection i have a document this document is in the form of the json document okay is it clear so so what i am saying here i want to go and create a new one so i will go to the vs code okay say that okay so i will tell you something here what i am telling that which is very important so you have the one server okay there is a server inside the server you can create multiple databases you can say db1 and db2 okay like that we can create a number of databases again in db and there is so many uh collections will be there so collection one and collection two like that will be there and each collection again there is a document doc one or we can say complete name document one and document do will be there and these documents are nothing but json documents basically you are writing so that is the reason we are calling this mongodb as document oriented database because we're actually storing the documents here okay we are actually storing the documents here so this is a json document so there is a server in the server i can keep multiple databases and each database can have the multiple collections and each collection can have the multiple documents and each document is having the multiple records or we can say multiple i mean we can say records only but because this is one document or multiple documents so this contains the databases document one contains the data okay you can create one number of documents and we can see this information okay and also one more important thing go back to the okay so here in the command prompt shell we can use this find function inside this you can put the curl process also it's fine if you say that same query only you can use the empty functions db is nothing but its current database db is always stands for the current db so you are already using the db name that is the dsteam and db.skill.find and if you are using the find means it will get all the information so basically by default you are using the curl resistance all the documents for example let me connect with another database in my local i'm going to use the scm i don't know what is there i want to bring okay i want to see the collections here right how to see the number of collections because i don't know what collection is there here right yeah so many connections are there i created this one some time back but i don't know what is the collections are there so how to check that what are the collections very simple code show collections so i'm connecting to the new database show connections there is the products here collection name is the products so if i want to get the data so db dot products and dot we can use find method and we can enter here these are some products of the samsung product sony product dell product okay something delivery status and all this information is there for example if i am going to use this same code with the curl braces inside enter you will get what same data only samsung sony dell only right so that is uh you are passing the empty dictionary here to get this complete so both the queries are same only okay and also if you want to see the data here if you can go to the uh i don't know it is icm right sem the products and you can see the same information even in the compass okay so any questions here before because i am continuing this one instead of this let me answer your questions do you have any questions guys anybody have any questions is this is it understandable or like do you think like there is any difficulty no it's a it's understandable okay yes okay good question whether the nested document will be applicable absolutely we can write the document inside the document also you can write document inside the document so the most thing you should remember immediately in your mind this text guys this is important today's session whatever you remember or not remember just leave it but this is important there is a server inside that there is a multiple dbs and each db there is a collections and each collection is at the end where we are used we are talking about the documents if we go to the uh sql databases at the end we talk about the tables in similar fashion in the nosql databases at the end we talk about the document so that's hence we are calling it as a document oriented databases okay so this is about this and we can also use the document inside the document also that could be possible that we can use it we can use it here okay so right now the question comes uh let's go back to this okay you are not created the skill okay now i will switch to the let me show you something here i am going to switch back use and there is something called ds team i'll enter the dst i am into the ds team i will use the show collections here and enter and you will see the skill but i am not created the collection separately i created this collection with document itself so if you can go back to [Music] yeah you can see uh the one which i am highlighting here directly i created a document but skill is not there but i created it because automatically it will be created but specifically if you want to create a collection okay we have command called db dot create collections for example db dot create and we can use the command name call collection something like this but people used to do mistakes at the time of learning this collection we are have to use c is uppercase letters this is account something we can give okay we can give some name of the collections here so you can collection name is what guys what collection name we can give anything we can give say that apple don't know some name came in mind just enter this it's saying that apple collection is created if you want to see the collections you can enter here show collections and you can see apple and scale so you can enter the n number of documents here this will come and can show you but question comes by default i updated this some document i need to update the information also but how we can do how to update a document is a question right so we can easily update the document guys by using the uh update function and uh that also we can do it so db dot some collection name dot update and we can update that one as well okay so let me write insert uh inserting the multiple documents then we can also try that one so instead of writing this whole thing here because we are most talking about python programming so instead of using this command prompt and the compass so if you think like okay raja these are all like little uh so much complicated can i write can i go and create it here yes you can go to the ds team and go to the here okay you need to refresh it you have to refresh it and see the updated collections here there is the apple i will go to this and there is no data here okay we need to add data so insert the document if you have the file you can insert and also you can see this there is a two ways okay you can also use it in the multiple ways if you are going to create it here insert for example if i say insert just only document is created but if you want to update it okay copy the document update the document this is edit document we can update it so by using the interface is easy okay and also there is something called aggregation schema explain plane indexes validation this is the advanced concepts we can discuss maybe in tomorrow because if i tell you everything in one day you may not get the information in by just in one session but so this is just basic idea i'm giving it you guys you can see here i don't know whether you observe it or not it's saying that okay the host is the local host 27017 the cluster is the standalone cluster that means only one cluster here and the edition is community edition and all this there is a 19 dbs and collection 13 collections are there okay fine let's go back to the documentation so here i want to download the mongodb uh so what are the mongodb the python i'm going to type here python mongodb uh what i can say that tools not the tools we can say it is a driver i'm going to enter here so if we go to the direct i'm going to direct a website of mongodb itself so for every language they mention the drivers let's go and look into the c driver so they have mentioned some c drivers here to connect with atlas what is the compatibility is there all this information is there so even ruby drivers python drivers scalar drivers java so mostly people use the java java combination so we also have in the java mongodb driver so we can also download it here all the steps which is the compatible which java version is compatible uh which java driver version is compatible eight so now people are using 11 that information is also there let's focus on python now so python is mongodb saying that a recommended way to work with the mongodb from python is pi and the motor is the recommended mongodb python asynchronous driver these are the two drivers okay i'm going to click this pi and it will show you that how to install this one it is very easy to install pi if you are very specific to that one we can install it and you can also go and click on this installation so it will directly take you to python by documentation from their website to this pi documentation it's a very easy guys uh we can easily install it and do it so that's simple i will show you one programming here let me go and create new window and how to do it basically so yeah so very simple code it won't take much time so open folder and i'm going to create uh python and mongodb okay mongodb just enter create a new folder in your local okay so i'm creating the new window just close this and we can create here and i'm saying that python dot py you can write any name i'm just writing this name so python dot py okay first i need to install the um it is a third party library or we can say driver so let me install it so i'm just deactivating my anaconda environment spelling is wrong deactivate um okay so i'm just deactivated the environment here so i'm going to install now okay pip so i have the two versions of the python in my local so that's my reason i'm going with the 3 install and the pi so py mo ngo if you are a little doubt on this you can um you can go to that documentation and you get this one pip install pi okay so i'm going to this and enter my okay so previously i installed this pi into the virtual environment now i directly installed into the my computer itself so it is installed there is no any third party tools is recommended to download here directly it is installed now i am done with this you can use control k and um let's write the programming okay so to to begin with this pie maybe you think uh how to start with this one how it will be it's very simple guys um i don't know whether they're mentioning your the tutorials okay i think there is a documentation i want to show no right okay no problem okay i think there is any steps here okay i think there is a documentation i will share with you and here i am going to write a simple code you can easily understand how to create uh a document how to create a collection all these things very very short way we can finish it off so we can use from and pi so this is the pi and import and we can give the class name is called client okay so from this it's same code same the what we are done with the force similar kind of thing so now i am going to use the i want to create the connection our client we can say that client is equal to and client which we imported just few minutes back okay so client dot are like you can also use this client function if you want to see whether the connection is established or not so we can use the print of client if you think instead of client if you want to give the connection name you can give okay it will make easy for you okay so it make something easy and i'm going to create i'm going to execute this code and do you see that connection is true so this is correct and in worst case scenarios if you are using a different port number that name if you can also write the same code in different way so connection one equal to and client and inside that you can also pass the which server you are using is at the local host we can mention the local host comma and we can use the port number is so 27017 the one which you are seeing at the bottom right 27017 okay and if you see when we can go with this line number five when you are using the different port number or different server okay the time only required otherwise by default it will take the local host and 270107 is the port number now i am going to print this now this is another way of establishing the connection between your python programming and mongodb i'm executing i'm executing this what is this guys okay i don't know why previously so client there is a two connections are established here so so both the codes are same only either we can go with the this code or we can go with this code both the codes are the same only but don't do so if you're seeing any documentations or any code you're seeing don't think like that but if you are changing this local host or changing the port number then you can use this okay so once connection is established we need to connect to the database right okay so i'm going to connect to the database now so we can say that database equal to and we are going to use i'm going to use the first connection only connection dot and which database we are going to use the database name is i created what your ds team right okay so dst this ds team i am just writing it directly right so if you want to bring this information we can go and use it's very simple to use this coding here mongodb so you can just print your and it's printing the correct but connection is true everything is true what if i am doing the wrong name here okay i'm going to give the wrong name ds team i will not queue i will give the dst x2 if i go and execute this code uh there is a there is a do you see something any differences here you are not seeing any differences right because by connection you are creating again database here so for example see instead of writing this i will say test 345 example it won't throw an error okay connection dot this to new database it will create a database automatically if there is no database it will create a database this command is nothing but internally this command is nothing but use is command is nothing but use what is that database so by default database will be database instance will be created in the uh server okay so we can say like this now i want to connect with i want to connect with the document i want to uh insert the document or i want to show the collection so how we can write guys i want to find the collection dot or something like find one so let's let's let's get the collection now so i'm using the collection object equal to now this connection this is the database right so first you connected with the server from the server you establish the database object from the database from the database we have to go to the get the collection so database dot what is the collection name here can you please tell me what is the collection name so i will not use this name i will use the name called ds can increase ds team right so what is the collection we created in the ds team anybody remember skill right yeah so we can use c it's a very like a chain process guys i'm going to keep this code into the comment section then you can ignore it first we establish the connection that with the connection we are calling the this dst which is nothing but database with the database we are calling the which one uh like this is called collection now this collection from this collection i want to print the uh records so documents it's very simple we can use the print statement and collection dot collection dot find you can see automatically this is showing up here the find find one now i'm going to execute this code we'll see that the data is getting or not yeah we are getting the data from the database there is something which we inserted some time back that's called ai programming that's what we are looking at here right now i want to insert a document you can go for this collection dot insert okay so you can insert one record or you can insert multiple records that can be possible here but you need to say that the collection dot insert we can we can write it separately or like we can go with the many also so i will go with the many instead of using one by one so instead many so what we can do right uh here i need to insert the multiple records so i'll create a list python list first that list i will pass it to this insert menu so to create for example multiple skills i'm creating here and what i can say that skill underscore many and this is the python list sorry okay so i'm going to create a multiple list okay in the sense in the list and each document document is always represents by using the dictionary so i'm just going to say that a name okay and the name is what skill here i will say this is numpy i'm just giving some skills and we can also give different okay say that this is uh like you have to separate it by each item is separated by the comma and here numpy it is a scipy see here i am writing only one inform one data only one row like if you want to write multiple rows you can write it but i am not giving that much information at this moment but we can write it okay so documents we can write it now again i am writing one more name and see i'm just keeping it into this name colon and we can say it is a pandas something like these are the skills now i'm closing this one with the square bracket i inserted the three documents json documents and i'm done with this now what we can do with this guys can i use the skills many as object okay already using the square bracketed below i'm going to remove it so i will pass this here because to insert the data let me correct this is how we can use it directly so what if i am going to use if i am going to run this code so i i'm going to execute this code so this is done i want to see those records so for time being i will put this one into the comment section i want to get all the collections i'm going to use again this statement so let's go and use this one collection dot find one if i go and execute this code uh do you see any differences guys only a programming result how to get this information find one again only one is coming up can you please tell me how to get all the data so shall i use this so this one and go and execute this still i am seeing the same thing but in this case you need to get each document for that we need to use the for loop again so for dock each dock in and all these docks are there in the collection dot find okay so i'm going to use this collection dot find and uh this is the find method you can close and put the colon and you can print each dock sorry print each document okay print off dock okay so i'm going to print this see all the information which got printed but you can ask me the question why a programming is inserted multiple times maybe somewhere we are inserting or like previously we are inserted into the here so to get all the documents to the python programming first you get the find one or find method this find method will the collection dot find and this talk document will be we are iterating to this list basically we are getting all the documents here and this id is nothing but a primary key we can say when in similar in sql we have the primary key this id will be this because documents are scattered right it is not placed in the sequence order it is not placed in no order here it will just like in uh yes these documents are scattered into the just a plane or database okay so that's where these documents is there you can create so for example uh if i'm going to add here something like this name saying here saying that yes and colon i'm saying that six so okay only one document i am just trying to do it here instead of saying that skills many one or two we can change it here and here i'm going to insert this because this is commented i'll use this one as a 2. now you go and insert these queries and you can see the ear c6 is which i added so numpy is asked is is there but i added the year cs6 i added some data but it is got appended here basically okay so it is not appended and so previous three records are asked is it is that numpy scipy pandas again i inserted the same data because i am actually doing the duplicate here i can do it basically but the duplication is uh the only way we can say that the id is different for each document okay that's all we can create it guys okay so you can practice this one tomorrow what i will do right i will go with the uh very advanced mongodb so i think it's a fair enough for you today and we can continue this mongodb with the advanced level and with often over 30 minutes or 40 minutes then after that we'll move on to the cassandra okay so yeah we can also use the find all function yeah right we can also use the find or right right right right we can use the find all also yeah yeah that's right uh but uh something is okay i think the find is als i still remember find all is actually capturing the same elements we need to use the talk function again so in the sense iteration is required at any cost iteration is important so this is about some idea about mongodb how to use how uh we can install it how we can connect with unknown but tomorrow session i will go with the very high advanced and uh and actually in the real-time projects how we use we'll get some idea so hopefully this is you got some information guys i feel
Info
Channel: IamPython
Views: 249
Rating: 5 out of 5
Keywords: Python, python programming, datascience, machine learning, PostgreSQL, sql database, python PostgreSQL, psycopg2, psycopg2-binary, Python programming databases, iampython
Id: OfByOwHWVPE
Channel Id: undefined
Length: 65min 44sec (3944 seconds)
Published: Mon Jan 18 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.