MongoDB Tutorial | MongoDB Course | MongoDB Training | Intellipaat

Just another WordPress site

MongoDB Tutorial | MongoDB Course | MongoDB Training | Intellipaat

hey guys welcome to the session by Intellipaat do you know that MongoDB was first worked upon in the year 2007 and after that it became one of the most popular no sequel databases and according to stackshare uber lyft and Codecademy or a few among the 3,000 companies who use MongoDB in their technological stack and this session we’ll be looking at MongoDB comprehensively also guys before moving on to this session please subscribe to our channel so that you don’t miss our upcoming videos now let us take a quick glance at the agenda first we look at what is in RDBMS and the types of databases with their limitations and moving on we look at what exactly is a no sequel database at its features moving on we’ll have a quick introduction to MongoDB with its benefits after that we learn how to install MongoDB and Mongo chip moving on we look at the different data types in MongoDB and finally we’ll be executing some basic crud operations using MongoDB also guys if you want to do end to end certification training on MongoDB Intellipaat provides a complete MongoDB certification training and those details are available in the description now let us begin this session well what are the prerequisites that you require for going through this MongoDB course a very very basic understanding of what exactly is a database I am sure you must be working with a database almost on a daily basis if you are working for a software company a Microsoft Excel is actually a database management system but remember it is not a relational database management system well let us see what is the database database can be defined as organized collection of data all the when you use this term database you entire you refer to the entire database system the system that handles the data not only data but transactions are problems with transactions or any other aspect of the data and this whole configuration is termed as a database management system now earlier designs and implementations were based on the use of linkages or sometimes called relations between data and with specific other form of data but these models were not standardized they required extensive training in order to make efficient use of that now what is a relational database system it uses the notion of databases separated into tables where each column represents a field and each row represents a record this notes will become more important for you as you go through this course as a reference when you are returning for interview or when you’re making a career shift or when you’re writing a certification exam in MongoDB so a relational database uses the notion of databases that are separated into say databases separated into tables where each column represents a field and each row represents a record okay now a simple example is an excel where you can see these are all this is basically a table which consists of all these columns and then these rows this is a database management system a DBMS only another example of DBMS is Microsoft Access but it is more than that it has got a primary key and also a foreign key okay so a relational database uses the notion of databases separate it into tables now this is only one table like this you can have many many made tables and if I configure this as a table with employee ID then address then gender then phone then email okay this is one table either say a table one I can create another table and by saying I would say status or the employment status whether he’s still on rolls or permanent or contract and so on the employee first name and the employee last name and then you have the employee ID let’s say you have an employee ID of one whether address XYZ for now gender female phone in this format and an email at the rate is a comm okay the random email I just created now here you have as a permanent Frank and then Smith and

then one the same employee Frank Smith who has got the employee ID of one has this address gender four and so on now what is the relation between this table 1 and table 2 now imagine this at a very very micro scale now in this excel sheet if you expand your imagination for a multinational company where employees records for payroll for compensation for HR for sales for so-and-so for the performance review for the number of sales or the quantity or the price of those sales done whether it is in the finance department or accounting department and you know there could be so many departments and big companies how do they maintain such records it’s cumbersome it is complex how do they check from a different table whether this employee is staying in this address or in a different address how do they make a relationship between this employee ID and this employee ID so these are all the questions that we will look at in a larger way in relation databases and particularly in Mongo also ok guys a quick info if you want to do an end-to-end training on MongoDB Intellipaat provides a complete certification training on MongoDB on those details are available in the description now let us continue with this session let us go back here and see so relation database can be defined in this format now these tables can be related or not okay so here as you have seen in the earlier excel sheet so tables can be related with each other with the use of something called foreign keys foreign keys are also called as common columns in that case the employee ID was the common column so the tables represent entities such as users customers suppliers and so on this will help you in understanding the database particularly at the time of designing a database schema for real-world objects that need to be mapped to the database in addition to the relations between them okay as you can see here traditional databases have organized collections of data they have this notion of tables different tables and how they are connected they have the concept of primary and foreign keys and then there is a design schema what is the design schema if you look at this this particular thing is called a schema where you have three different tables one is the users table with user ID as a number username the password and the email we have another table called purchases sale ID item ID a user ID sale date and quantity and then the items table where you have the item ID name price category and a description now an important design aspect of relational databases is the normalization of a schema now this particularly involves three steps one is called the first normal form then the second normal form and then the third normal form but how do we arrive at these three different tables we do something called a normalization of schema what is normalization normalization in plain English means making sense of the entire database so it is the process of organizing the columns and tables of a relational database to minimize the data redundancy so that we don’t repeat the data in many many many tables and how do we normalize this particular structure of of let’s say an invoice and invoice as you know has usually an order ID it has item ID so in the same order ID or the form you can have item ID 1 2 3 4 and so on you could be purchasing computers accessories mobiles and so on now when you have such invoices in large quantities how do you represent those in the actual database in an RDBMS so these are the three key steps that are followed and the first one is the first normal form which means there should not be any repeating elements or groups of elements the second one is no partial dependencies on a concatenated key we will look at what exactly this and third normal form is when no dependencies are there on key attributes so have a look at this one let me just make it as a

full screen so don’t repeat these columns that’s the first normal form so you have your item ID 1 item ID 2 so 100 could be you know a mark I 101 could be a Dell and so on but they’re all part of a single order ID and the order ID is one so the way we do a correction of this is in this format order ID which remains the same because it is for a single invoice and then the item IDs which is 100 101 and so on so this portion right there these two columns are done in such a way to reduce the redundancy as you would typically write in an excel sheet so we never repeat the elements or groups of elements in a single table that’s the first normal form the second normal form is as I said no partial dependencies or a concatenated key now if a column is not related to the primary key then you should break out the primary key into different tables okay now here the primary key is order ID and item ID how do you determine which is a primary key a primary key or a primary key word in fact is a key in a relational database that is very unique for each record it is that unique identifier which could be you know your social security number a driver license number or a telephone number or your vehicle identification number these are very unique to you so a relational database must always have one and only one primary key so here in this case we have order ID as the primary key when you have two primary keys it’s called a concatenated primary key it’s like saying a primary key is a combination of order ID and item ID so this together forms one primary key very unique identifiers in a particular invoice now what do we really require order date here in this table so an order always occurs at some time but is an order date really related to the item ID it’s like saying order ID will always be the same for a given order order date will be the same for a given order ID because you have received the invoice on a particular date and all the item IDs on that particular date will remain the same okay so regardless of the value of the item ID column so this means data duplication so you denormalize so the way we correct it is in this format so we bring orders and order item separately and we put order ID that is attached to order date so I order date is not really dependent on item ID but it is actually dependent on order ID okay not on item ID but on order ID in a single order ID you can have multiple items receiving on the particular so this is actually normalization it’s making sense of the relationships between the the attributes of a particular table and here an order ID and item ID they together form at this wonderful primary key okay now we are all trying to establish whether a particular order on a day it relies really on a particular item ID so it’s not so that’s why we separate and the third one is called the third normal form which means no dependencies on non-key attributes okay now this third normal form is meant to cover the single column keys which means you put all the columns that are not related to the primary key into a different table okay so like example order date customer name customer city and so on so this customer information can be really a separate table so you pull out the customer name another customer feels into a different table and then you put a customer foreign key into the order so this portion can be in a different table and then that particular customer foreign key can be put inside this particular orders table so you are actually categorizing the whole process to make sense and make an order out of these these tables now the other thing about the traditional databases and the benefit also is called the acid properties now what what our acid properties a stands for atomicity this is consistency I for isolation and D for durability it’s a set of properties that guarantee that the database transactions are processed with a great reliable factor okay so what is the transaction a logical operation on the database is called a transaction so

we’re making sure that is all these transactions can be relied properly because of these acid properties now atomacity means without going into much details because this is basics 101 of the database a Thomas T is either all parts of a transaction must be completed or none consistency is is talking about the integrity of the data in preserving all the transactions so you don’t leave any invalid state after a transaction isolation is when a transaction must be run isolated in order to guarantee that any inconsistency does not affect other transactions that’s you ever that’s when you isolate a particular transaction that durability is when the change is made by a completed transaction must be preserved after transaction is completed it must be preserved must stay back in that particular database so there are few traditional databases which many organizations use like Microsoft SQL Server Oracle database MySQL IBM db2 these are some of the popular traditional databases that exist out there so let’s look at some limitations of the traditional databases okay guy is a quick info if you want to do an end-to-end training on MongoDB Intellipaat provides a complete certification training on MongoDB on those details are available in the description now let us continue with this session one is scalability for large databases especially those that are used for web applications the main concern is scalability as more and more applications are created in environments that have huge workloads the scalability requirements can change very quickly and can grow very large relational databases and they can scale well but it usually is it is when that scaling happens on a single server so we call that as skip scaling up scaling up is when you have a single server where you had initially about that’s an 8 gb ram okay and you’re now going to make it a 32 gb ram you had the server size as 2 terabytes and you’re going to scale it up to about 16 terabytes so this is Scaling up a single server this is good for relational databases but when it comes to scaling out when the capacity of that single server is reached then you can’t expand it any more and when you can’t set the configuration or upgrade the configuration of the server anymore and then that’s the time that the scaling out time of the challenge that’s when the our DBMS poses a challenge in terms of distributing that load across multiple servers so the scaling out is basically you distribute the load across multiple servers moving into so-called what you call as distributed computing so this is when the complexity of relational databases starts to give you some problems at the scalability factor if you try hundreds of thousands of servers the complexity becomes even more and these are not cheap servers every server that you maintain needs to be a very high scale high configuration memory intensive or compute intensive or storage intensive kind of server so though this is one of the main challenge of RDBMS the other one is data complexity relational databases can save structured data very well but not unstructured data structured data you all know which is strings integers boolean float etc so these are all basically can’t they come into the purview of the structured data but think about music files how do you analyze them think about image files XML files emails and a good example could be a Facebook like what data type would you attribute to this particular Facebook like so it is these are all part of what you call as unstructured data so as unstructured data keeps on increasing these days the data complexity becomes even more in terms of handling inside the RDBMS then you have the broken keys sometimes when the keys fail the primary keys with the foreign key connection fails because of these earlier two issues and then you have a database predominantly where there is no relationship that exists absolutely then in every kind of RDBMS you have to define the schema before you load you can’t load and then define the schema so it takes up time whereas in the other kind of databases which I’m

going to speak about now called as NOSQL you don’t have to define the schema before loading you load it you analyze it even if you do not define the scheme also it is fine so that’s where the the biggest limitation of our DBMS is these for scalability complexity of the data in terms of the structured and unstructured format the broken keys of and the relationships between primary and the foreign keys and then definition of schema before loading it let’s look at a non traditional DBMS that’s called as NOSQL which means no relation SQL it’s a form of database management that doesn’t have any relationships this term was coined in 98 by Carlos Rousey the data that had NOSQL type of databases handle is more complex and there are many no SQL databases that exist out there so no SQL databases started gaining popularity in the early 2000s when companies began investing and researching more into distributed databases that is why you have got many many database categories inside NOSQL some are based on document stores some are on key value store some are graph based and so on an important aspect of no SQL is that there is no predefined schema which earlier you have seen one of the challenges of RDBMS is overcome by no SQL that is one you you have no predefined schema and then the records can have different fields as necessary and this is something called as dynamic schema many know SQL the databases support very advanced features like replication and all servers in fact they execute the same transactions and synchronize the data an important difference between relational databases and No SQL is that they do not fully guarantee acid properties it’s because it’s is their deployment architecture which typically involves having multiple nodes in order to achieve horizontal scalability and also recovery in terms of any in case of any failure so this deployment and synchronization is very very effective NOSQL use API is or query languages to access and modify data they also use the latest hadoop mapreduce methods which is used for performing a specific function in fact the popularity has written more on the wave of the big data and there’s a lot of confusion in the market as to what exactly is big data well before we go into that I can tell you some differences between SQL and NoSQL the SQL databases are table based databases whereas NOSQL are different formats like document based key value pairs graph databases or column stores etcetera so whereas an SQL database you represent data in the form of tables which consists of n number of rows no SQL databases are the connection of these same documents or key values whichever depending upon the no SQL databases which do not have a standard schema definition SQL databases are vertically scalable whereas the noise scale databases are horizontally scalable how do you vertically scale an SQL database by increasing its horsepower of the hardware as I said earlier regarding the RAM or the processing speed the hardware the storage it’s all about increasing the horsepower by vertically scaling up no SQL databases are scaled out horizontally by increasing the database servers in the pool of resources so that the load is distributed optimally SQL databases they use SQL which is structured query language as all of you know about these things SQL stands for structured there’s no unstructured type of structured query language for defining and manipulating data and manipulating data it’s quite powerful in NOSQL databases the queries are focused on a collection of documents typically I’m referring here to MongoDB they’re also sometimes called as unsql QL it’s a kind of an informal word which is unstructured query language it varies from from database to database there’s no technical term like this but it is

what is informally refer to SQL databases are MySQL Oracle and so on but isn’t no SQL you have got MongoDB you have Redis you have Cassandra HBase you have new 4G and a host of other CouchDB DynamoDB and so on which there are all types of noise Kuehl another difference is for complex queries SQL databases are a very good fit because it has got that query intensive environment you use the where clause and so on and so forth whereas no SQL databases are not good fit for complex query if you want to do an end-to-end training on MongoDB in telepods provides a complete certification training on MongoDB on those details are available in the description now let us continue with this session yes so these are the key characters and characteristics of no SQL data now let’s look at why no SQL is is gaining more popularity these days what is definitely because it doesn’t consider the relationships that is there for traditional databases and it helps in dealing with unstructured and large data sets of the loads of which can be distributed across different database servers secondly there is no schema at the time of loading it some of the other motivations for taking up the noise clear is not having to deal with impedance mismatch between the object-oriented approach to write applications and the schema based tables and rows of relationship relational database for example storing all the customer order info in one document as opposed to having to join many tables together resulting less code to write debug and maintain so that is one of the simplicity’s of the the design of noise QL and then Auto elasticity which is you know you have better surahs on tool scaling to two clusters and machines which really solves a problem when the number of concurrent users increases for applications that are accessible via the web and the mobile devices so using documents makes it much easier to scale out as all the information for that customer order is contained in one place as opposed to spreading out into multiple tables and these no SQL databases they automatically spread data across servers for load optimization without really requiring application changes which means natively and automatically data is spread across a number of servers without the interference of the application or the application to be even aware of the of the server composition so the which really benefits the data and query loads because of the balancing or auto balancing that happens across the servers also if one server goes down it can be quickly replaced with in fact with zero application reception so a lot of failover scenarios are taking care including very high availability and you have also finer control over the service or the noise kill data service which can be really added or removed without application downtime most of the noise clear databases they support data replication the store multiple copies of data across the cluster and so even if one cluster is down it ensures high availability and specifically disaster recovery it has integrated cashing facility it has a very very simpler data model it can easily capture all kinds of data that is related to big data these days big data is is nothing but it consists of four main characteristics there are textbook definitions for volume velocity value and you know variety of data so the text books really define that if the volume of the data is increasing and the rate of data is different which means it includes a structure as well as unstructured data and then the volume the variety and then they of course the the value addition of this data that is there that how much of the data is really valuable for us but before that it is also the velocity of the data the speed at which it is coming in the volume the variety and velocity have been traditionally defined as comprising of big data now people are adding value and also velocity the truthfulness of the essence of the data that is actually coming up and so there could be a few

more visas also probably in the future so the volume of the array is huge if there is a lot of variety in the data the velocity of the delay is coming very quickly then you really have a big data challenge for me the four main characteristics are some of them are included in this data increases continuously okay what does this mean you must have all heard about Angry Birds application on mobile it’s pretty old now but you know let’s take a very very popular application in the mobile any-any popular mobile application when when 10 people downloaded the effect on their server on the company side server is not huge but when million people download it in a week then the amount of load that the server has to take in a week really increases and puts a challenge on the server capacity so one of the characteristics is data should be increasing continuously and then the second one is data is both structured or unstructured people also call semi structure but I would comprise it in non structure itself so unstructured data is what we have earlier discussed and it is difficult to analyze okay so let’s say you have to analyze one terabyte of data it’s not really easy to do that because of the unstructured format and also because of the volume of the data the velocity of the data that is coming in difficult to analyze within a certain tolerable time limit if I wanted to you to analyze one petabyte of data in one month or whether it’s a one week it’s huge I mean normal traditional databases cannot really do that to give you an idea of how much is one petabyte of data you know a normal blu-ray disc okay which has a movie high-quality movie I will have about 2 GB of space for 2 hours of movie right so if you have to watch one petabyte of movies continuously okay then it would not take you it will actually take you more than 30 years to complete watching 1 petabyte of movies continuously so and face book deals with about 400 petabytes of data every month that’s the volume that they deal with eBay Amazon and so on so if Mark Zuckerberg the Ox asks you to you know give him the result of your analysis which is how many people in the last five years have been using on facebook on Windows and how many have been using on Apple the Mac computers and where the usage is more and he wants the result in the next two days or one day in other words you’re fired then imagine you’re high your problem then but the advantage is such kind of no sql’s of course intermingled with powerful frameworks like Hadoop really can’t take care of such as not only storage but also the analysis part of it ok so if you go to a company and if they say to you yes our data increases continuously yes it is structured as well as unstructured yeah it is difficult to analyze and also within a certain tolerable time limit you can confidently say that mr. X you do have a Big Data challenge okay Big Data is a concept it is not a technical framework it is only a concept ok so Big Data which usually consists of such kinds of structured and unstructured data can be easily captured inside no SQL databases because no SQL allows you a flexible framework that can accommodate any type of data and that is not disrupted by the structure of the content chain content of the changes in the content itself because the the document database of MongoDB especially schema-less which means you can freely add fields to JSON documents without defining those schemas so there is no it is schema on reading instead of schema on right so you fill in the data information inside and then it will give you the you can read it after you you can read the schema without really entering the schema on the right in the beginning ok you can have different number of fields you know that contains a lot of combinations of data types also speed is

one big advantage of no SQL the data structures used by no SQL that is the json documents they differ from those used by the traditional databases making many many operations faster than our DBMS because you don’t have to join the tables there is no concept of join in Mongo especially so at the cost of increased storage space your duplication of data and so on there is no really join that is happening but storage space is very very cheap nowadays because you can buy commodity hardware so most noise ql databases do not even support joins so it becomes very very quick to analyze because in joins you do you know you have multiple tables you have multiple where clauses and all those filters that are there whereas Mongo can give you a great advantage in addition to this the the noise ql databases usually use clusters of as was just saying cheap commodities servers so there is a huge savings on the cost whereas the our DBMS tends to rely on the expensive proprietary servers whether it’s IBM whether it’s a Microsoft and any other storage systems not so remember the licenses for our DBMS can be quite expensive whereas no SQL is open source and and it is free okay so these are all the differences between the MySQL and no SQL no SQL databases are being used more in big data and real time applications and those systems are no SQL people also call as not only SQL okay not only SQL to emphasize that it also supports sql-like query languages so Mongo and so on the support is so on top of certain frameworks you can do your SQL queries also but some reason that block the adoption of no SQL include include the use of a very low-level query language because SQL is a very powerful structured query language whereas no SQL doesn’t use a high level equivalent query language so that is one of the reasons that you know people usually do not go for no SQL but nowadays it is not a problem many many many companies have come forward for that integration and so the apart from that there are not really big challenges for NoSQL some people complain about security but hey Lennox is also open source right so but a lot of people use it because it’s a community-driven and the security in many years has really increased a lot and similar thing has happened to notice QL also know SQL databases also use different kinds of GUI as well as command line interfaces similar to our DBMS as you can see there are different types of new SQL databases its document based or key value based or column based or graph based there are many many categories in the document based MongoDB memcached in the the key value cassandra more in column base new 4j in modern graph but overall if you look at it Mongo supports a lot of features there are also all GUI environments that help you to do monitoring and and administration of your database systems one of the severe limitations of relational database is that each item can only contain one attribute so if you use a sales example a customer’s relationship with the company is stored as separate items in separate tables so the customers master details are in one table the account details are another table the sales details in yet another the bank alone details is in a different table and so on so all these tables are linked to each other through the use of relations like primary and foreign keys non-relational databases are radically different from this model they allow you to store several related items in one row of data in the same table ok a radical difference I just like to write it here a radical difference is it allows you to store related items in one row in the same table okay and this row is not same as I’m not referring to the our DBMS or the table kind of row that’s why I put it in court

so in all non-relationship you know for each sale each row would contain the customer details as well as their account loan and and also a lot of other details so if you look at the example here here you have address gender phone and email and so on right so at a similar example for no SQL would look like you know you have your X Y Z comma a female comma X at the rate Z calm + 1 + 3 – 3 7 you know whatever the number is there and this is a la number so say in physics a ok so all these things can be contained in a in a single row okay we just wrap it up so this is how it would look whereas here you need to have one attribute part row it’s a radical difference now it’s it would seem to be a superior method of storing data well ETH has its own advantages and disadvantages so in this case you have all the information of the customer of the employee here in this case stored as one data record ok the customers transactions would be stored as another data recorder it’s a big big difference here an advantage of our DBMS is that it has a way of ensuring that your business logic and the rules on top of the database layer still remain the same through primary and foreign keys whereas no SQL that responsibility falls directly on the application logic and few people are really comfortable leaving this just to the application so they do try to use our DBMS because of this lack of enforcing business logic inside no SQL because when it comes to web-based applications that use databases rigorously enforcing business logic is often used as a as a top priority so it is the ability to service large number of user requests which are typically read-only requests so a site like Amazon the majority of users simply browse and look through you know the items which is like read-only operations only a few of them really do transactions to index like read and write operation also their credit card information and so on so we are really talking about billions of pageviews per day here I’m sure the Amazon administrators are more interested in quick response time to ensure faster loading for the site’s users rather than enforcing rules of insuring balances between reads and writes so that that is the real Challenger is the our DBMS is lack of scalability when dealing with specifically OLTP transactions okay lack of scalability in our DBMS for specifically OLTP applications or any in fact or any with lot of writes okay which is the type of relational SNP architectures this is where noise clear really shines they can distribute the data across dozens and hundreds of even thousands of servers Google and Facebook have thousands of servers and with each server handling a small percentage of the total requests the response time is very good for each individual user this distributed computing model can be built on top of relational databases but it takes really lot of time to implement especially when there’s a lot of rights so that is OLTP ok that’s your online transaction processing the relational databases it really insists on the data integrity at all levels ok which must be maintained in fact even as the data is accessed and modified by the servers and this is also other reasons that non-relational is taken up as a choice for cloud computing and social networking so on because at the initial level especially the right level you know it is not really required but the reach level it enforces the data integrity so at one at any point of stage they should be identity and so not and the our DBMS has its has at all levels and all stages which is minimized by the noise ql so for high transaction loads our DBMS really suffers because of a lack of horizontal scaling but as no SQL really shines because it can deal with high transactional loads and at half the cost of of what you do in our

DBMS with no joins and great analysis so please remember these different types of non SQL databases and also remember why I know SQL is it’s quite popular so integrated caching simple data model and so on so in order to increase a few more points just to add here on the slide in order to increase the data and increase the through and increase the performance of the universe ql techniques such as caching is also used in system memory this is very much in contrast to SQL databases where this has to be done using separate infrastructure okay so just took a few more points here for you so there is a speed factor okay there is an auto elasticity which means it can distribute the burden of the load across multiple servers there is no schema data and then it’s a very very simpler module also okay so what is document base what is key value what is column what is what is it basically this all these things mean let’s look at document based database okay the classic case of course is MongoDB so the document based noise ql can be considered the latest craze in fact that is taken that is taking a lot of people by by surprise and with this pleasant surprise so these document based databases they work in similar fashion to column based ones they allow very deep nesting and very complex structures to be achieved so there is this concept of document within a doc within another document see it’s like a hierarchical structure of documents that you can have and these are JSON kind of documents typically and these documents they overcome the constraints of the other kinds of databases so any kind of complex and arbitrary structure can form a document which can be stored using such management systems retrieving a value of a record means getting the whole lot of it and that goes for updates the slight performance little issue can be there but the the powerful nature of it quiet overcomes this this weakness and then you have the key value kind of databases so in key value you typically have keys with values similar to a dictionary so let’s say you have a word and its meaning or meanings okay so actually you have your key and values so there is no structure there’s no relation after you connect to a database like Redis an application can state a key so which means you know again an example is employee ID and then the value would be an integer for example of 42 41 or something which can be literally achieved the same way by supplying the key these are used for quickly storing basic information quickly storing basic info which are done after performing CPU or other kind of computation memory intensive computations really a dictionary is a great example that is usually used for Kewell because it constitutes arrays of collections with individual keys that match the values okay so you have in fact Mongo has come up from the word humongous okay it’s been taken from this humongous is huge huge data big data and so on so that’s why it has been used it will go into details of Mongo anyway and then you have your column based column based DB in this you have your example as Cassandra and HBase these work by a little bit advanced nature of key values despite their complicated understanding that is out there especially for HBase

for which the the the community support is quite less compared to the Cassandra the column base no SQL really do not require a priest structured table to work with the data each record comes with one or more columns containing the information and each column of each record can be different the earlier Excel example that I have shown can be done for column where you can store integers boolean all in one cell itself it has got multi-dimensional arrays whereas where where in each Key has more key value pairs attached to it so these are commonly used when the key value databases are not enough and you want to store very large number of Records with quite a lot of information in it column based database is used when you have unstructured data and non-volatile information which is if a large collection of attributes and values needs to be kept for long periods of time then you can have column based data stores which will come in real handy they’re also highly scalable by nature they can handle a really lot of information examples are Cassandra and HBase HBase is used as a data store for Apache Hadoop it’s based on ideas from BigTable and Cassandra is a column based data store based on BigTable as well as the dynamodb also and then you have something called the graph databases quite popular ones are neo4j which is a vast graph and document based hybrid no SQL that’s written in Java and that comes with different operational modes also neo4j is a scheme of free extremely popular and powerful Java graph based the datastore and these are also used when you want to handle complex relation information they made XD make an extremely efficient to deal with complex information such as connections between two entities various degrees of other entities and directly related to them for example you have linden which is based on first second and third connections it actually is based on the premise that you’re connected to anyone in the world by not more than seven degrees so the representation of that in using a graph database really becomes easier they also are very good in situations where you want some relationships to be involved like modeling data and classifying some information on on this type of data store a good example would be the representation of a graph database in terms of the Nords so you have one node which is connected to different other nodes so for example alice has got these relationships with the three departments and she belongs to all these three departments and she has got this label so a typical example would be of a database representation in graph database his based on so each node in the graph database directly and physically contains a list of relationship records that represents its relation to other nodes and these records are organized by type and direction and may hold some other additional attributes also so whenever you run the equivalent of a join operation the database just uses this list and has direct access to the connected nodes eliminating the need for a very expensive search or a match kind of computation and the neo4j has very highly scalable open source graph database that supports acid properties also it has high availability and comes with a web-based administration tool that includes full transaction support and kind of a visual node link graph Explorer it’s accessible from most of these programming languages it has its own built-in rest web api interface and among the graph databases it’s the most popular graph database now let’s look at some differences between mainly our DBMS and MongoDB because this is what we’re going to deal with in the future of this course so MongoDB is a document oriented database it is not a relation relational one the primary reason for moving away from the relationship model is to make the scaling out easier and a lot of other advantages also a document oriented database it replaces the concept of a row with a more flexible model that is called the document you can have embedded documents document within document and embedded arrays and

so this document oriented approach makes it possible to represent complex relationships with a single record there are also no predefined schemas a documents key and values are not fixed not of fixed types or sizes so without a fixed schema adding or removing fields becomes easier and this helps the developers in terms of making their development quite fast it has got very easy scaling these are the equivalent terms so you have a database and then a database within a database you have tables you have collections in MongoDB and in the table you have rows also called records in collections you have documents also called as objects now here also you have columns or attributes and there you call it as a field so here you have joins but there you have embedded links and so on so it’s used for scaling up very very easily it has got tons of features it supports indexing it supports aggregation there are some special collection types it has it also supports file storages which are easy to use protocols for large files and their metadata information so giants are not there and then complex multi row transactions are also not there it was a purely a deliberate decision to allow for greater flexibility and scalability because these two features are difficult to provide in basically a distributed system so it has got very very incredible performance – so there are many benefits to this as you can see here in the next slide it’s more or less a DBMS replacement for web applications it deals with semi structured content management with real-time analytics and high-speed logging it also has got caching and high scalability but before proceed further please remember and learn these important technical terms so a document is a basic unit of data for Mongo and is equivalent to a row but much more expressive and the collection is equivalent to a table a single instance of MongoDB can host multiple independent databases so it’s a great feature a single instance of Mongo can hold multiple databases each with its own collections ok and every document has a special key which would be represented like underscore ID and this is very unique to collections so every document has a special ID and Mongo comes with a JavaScript shell which is useful for administration and there are a lot of other admin gos available like more popular that I use is Mongo Chef that you can download and and connect with your Momo so everything is based on this document ok and what does a document have a document has got a key and associated values ok it with this document varies by programming languages but most languages have a data structure that is map has dictionary and so on so these documents are represented as such here are represented as objects so I would say in a JSON format Mongo for developers and then here I would say welcome to this course from intelli part ok this is how this is the most simple document that contains a single key ok so I would say mo Bongo for developers MFD ok here to eat just easily represented it’s called as MFD and this has a value this would be the whole welcome part of this value okay and then you have got really good benefits of this why you use MongoDB well I was just sharing a skill was invented in the 70s to store data MongoDB stores documents and objects everyone is working with objects these days and all these as programming languages are supported in MongoDB so we need databases to persist our objects so

why not store objects directly that was the concept which led to MongoDB so you have embedded documents and that is the reduce need for joints and no joints and no multi document transactions so a database is made up of multiple collections and which are created on the fly when you reference for the first time so you don’t have to say create collection as soon as you say a DB dot some collection dot something the collection is created it’s at the same time as it is referred for the first time ok so if you type in DB dot collection so the collection is actually inside the database the name of the collection is DB dot test so the test is automatically created as you type in you don’t have to say create tests and so on and a collection is a table again going back here database collections and documents the table which is schema-less and contains documents and the indexed by one or more keys it can be cleared on the fly it can be fixed size or older the COTS get dropped after reaching the limit you can also cap the size of the the collection there a document is stored in a collection it can have a special key and it works like primary keys in this ql mysql it has got embedded or reference based relationships and the document storage is in busan it’s a binary form of JSON a typical example of the document would look something like this so you are defining something called a variable P with a special ID author the title it’s an open source timestamp tags and then comments okay you want to post it in a blog so you just put a DB dot post is the name of the collection and then you save this information of the document which is P inside this collection called posts let’s look at how to install MongoDB for that you need to first go into the I this website called MongoDB dot o-r-g / downloads once you are here you can go to the download section or you can just cross the the scroll bar down and then look at various options for Windows Linux Mac and also Solaris you will have these options to install windows 64-bit if you are using Windows 7 or 7 plus including Windows 8.1 or 10 use the 64-bit 2008 r2 plus on your 64-bit machine if it is 32 then you can directly go for this this is an installer MSI installer once you download it and you double click on that so before you go there what you would do is let me just explain installation on Windows and I will go further into other operating systems so you download the MSI file or also the zip file so you have two formats in which you can do that so three in fact eg Z and zip along with MSI so I would recommend using zip file because you can extract all the files into a particular folder which you will be creating now which is create a folder like this you can just say MongoDB ok and now bring the zip file into this folder and extract files here now create new folders which would be and inside this data you will create two new folders because this is going to be the database path one is this one and the other is the log so now you create a text file called Mongo here itself in this particular location create a text file which is on the lines of Mongo dot config dot txt ok so inside this you need to copy some information which is going to be in this format you need to bind your IP address which is default 127 port number for Mambo is always going to be two seven zero one seven by default okay interview somebody asks you what support number default for Mongo it’s this one and this is the DB path that you are going to mention so if you have so please note that you need to use the uppercase and lowercase exactly as it is okay and then once you do this

save this file save the file and remove dot txt at the end so it would be only Mongo dot conflict okay so it’s not wrong but Mongo dot conflict okay and then once you do that open your terminal by in the administrative private the administrative privileges so which is going to be your the Windows key plus X and then you press the letter A okay so now here go into this by default you will have C something and then system32 so but come into this folder mongodb okay and now from here you type in Mongo d dot exe okay – config file you are referring to the C Drive wherever it is located MongoDB slash Mongo dot config okay now open a new terminal now what happens in this case it’s actually running the Mongo d instance so and in the new terminal go to the bin folder wherever it is located depending upon the zip files in this folder structure that you have of these zip files it does the bin will be inside the zip file ok and then you type in Mongo so it will come up with DB and then like this test let’s look at what is there inside so what this does is it binds the IP address or addresses to Mongo D ok and this is the port where Mongo D should bind to this is said to be true so that only critical events and errors are logged not everything that you do in Mongo is it really needs to be logged this is where you store the data ok and that’s the path this is the DB path actually to the where you store the data and this one here is the past of the log file – which Moncada should write it’s log messages ok then I have a log up into true so that the log is not overwritten upon the start of or the restart of Mongo D ok so this is written this is true so that the log is not overwritten upon restart of Mongo d instance ok just taken that I’m gonna save this notepad anyway okay so now let’s look at how to install in Mac so MongoDB installation on Linux yeah so you go to the same site which is MongoDB dot o-r-g and then you download the 64 bit or whatever 32 bit in here so in your case whatever it may be and then you save it okay you save the file to the slash home slash you know let’s say downloads ok so then you unzip in the same folder it will be a zipped file to do to unzip so the way you do it is by using a tar you can have many flavor of Linux Ubuntu zinthos you know Seuss Red Hat or anything but the command line will be the same so so basically you are unzipping the file which is the tar file extract zip verbose finds X CBF MongoDB – Linux and if you have this version then whatever that version is three point something dot T G Z okay then you create a directory by from the as an admin by saying mkdir slash Mongo slash data and from your downloads section so wherever

it is downloads okay from here you type in this one pseudo MongoDB – Linux – I 86 the version that you are using /bin slash Mongo D and then you give the DB path as Mongo slash data then you will see that it is waiting for connections it’ll also give you the port number two seven zero one seven okay so then open another shell open another shell and there you type in Mongo so anyway let’s you are here Mongo – Linux some version /bin slash Mogul okay now it will say connecting to test and it will give you the terminal like this so you can insert a simple JSON file you can also ask it to show you the DBS all the databases that exist you can say show DBS ok then here you can start using the MongoDB also if you go to any browser let’s say Firefox for example inside Firefox just type in this one localhost with a colon two seven zero one seven okay it will show you the details of manga there this is as far as Linux is concerned and if you need to look at Mac installation okay in Mac also it is pretty much the same as Linux so you download Mongo and you know you click on your Mac OS whichever stable release is there then go to the download section or the Downloads folder and then type in the same thing which is your ATAR XZ xvf also goes in Mac so MongoDB something dot tgz okay so you will see Mongo and Mongo D process here so make a directory mkdir & p / – / DB and then give the permissions all permissions read write and execute permissions on this one / data / go to the bin folder okay and then type Mongo D okay the port will listen to the two seven zero one seven open new terminal and then you type in dot the small go to execute that so your MongoDB will start running then so in my case going forward with the examples I have installed in C MongoDB and then this data inside the data we have DB and the log files also okay so this is the main structure one go D data the Mongo chef is a GUI which I had installed later but this is important MongoDB this data and this DB and then this log so this is what I have created so instead of saving data in tables Mongo DS tours JSON documents what is the JSON Mongo stores JSON documents what is the JSON it stands for JavaScript object notation okay so which will look like key and a value so you’ll have like a like name and then Frank okay and then you can have like a fruit and an array which basically the brackets are not correct but I’m just typing in for example saying and then orange and so on so like this you can also have so fruit is an array of apple pear and orange but this is not possible in our DBMS okay really not possible so the way you do it is in fact if you if I write the exact way it’s going to be in this format okay for fruit so this particular thing is not possible in our DBMS there are two basic data structures that are there in MongoDB one is called the arrays

the other one is called the dictionaries okay now these data structures are schema-less as you have seen earlier also the when we looked at the benefits of manga and the docs do not which means the docs do not need any schema all right so therefore MongoDB is a document oriented it has dynamic schema it does not have joins does not support transactions across documents and it doesn’t support SQL also okay so which features does Mongo omit to retain scalability which features does Mongo omit to have scalability if I give you four options which is indexes joins transactions across documents storage okay so it would be joins and transactions across documents okay now let’s go to the terminal I’m just on my window system so I’m pressing windows + this X here then pressing a at last for resize are now logged in as administrator I’m going into the Mongo DB okay so Mongo DB and go into the bin folder right now they’re two ways to do this one is by doing the Mongo D space DB path which is this one right there okay so you can type this so you can go directly or you can also do a net start Mongo DB because we have installed it as a Windows service also let’s do it the other way windows service format okay so what I will do is net start MongoDB so 3.2 version which is the latest one as of Feb 18 2016 it’s just started and just type in Mongo and so on okay so it has connected to the to the test collection now you can say show DBS it will show you that there is one database that is there which is the local database and we can start it in a different format also where if you put in Mongo de it will say 2 7 1 0 1 7 listening then you open a new terminal and then type in Mongo there so then it will open the same terminal where you can have your practice sessions this we have opened through Windows service if you want to look at the help then you can also type in Mongo and then help ok ok so you can have just type in help there and you can see lot of help functions which is debby dot help help on TV methods replica shell sharding show DBS names show collections show users show profile and you can also see a whole variety of the other ones also like dB how to find what you have inserted as documents so all these things can be checked yeah fine so we look at Mongo importantly so Mongo DB is very much case sensitive I just copied all the notepad information into a Word document so that I can do some formatting here so Mongo DB is case-sensitive ok and also type sensitive depending on the brackets or the syntax that you use you need to do it very very carefully ok so there is a difference between you know an X which is a 3 and an X which is like this ok so there is a difference

between these two and the other thing to remember is you cannot have duplicate keys ok so earlier I had used MFD and this one right so you can’t use the same MFD key again and again so let’s say you have this one you can’t use the same thing to have welcome to this you know welcome again say you can’t assign same key twice to two different values and the key value pairs and documents are ordered okay so whichever comes first so you can’t compare one with the other if you have two documents with one X 1 and Y is 2 this is not the you know the same as Y 2 and X 3 X 1 okay both are very very distinct you should not design your schema to depend on a certain ordering of fields MongoDB may reorder them so we will see how how those special cases can be addressed where field art is not really important in fact the default representation of a document does not even maintain ordering okay so the drivers for other languages like Python let’s say have a mechanism for specifying documents with ordering where necessary a few tips about the document itself and you already know what’s a collection it’s a group of documents that’s why we call it as a collection is a group of documents okay and the collections have dynamic schema okay so which means the documents within a single collection can have any different number of values which could be of different formats also of different data types for example if you have a welcome so MFD and X can be stored in fact in the same document okay one is a string the other can be an integer and so on let’s do a small example so now DB dot I have got something called things okay as a collection which I am creating earlier I had said you can create a collection as you reference it that’s an important point so DB dot things dot save I’m going to save some values okay so that is a is one B is 2 and C is 3 ok so I have here this one okay so after you entered this one DB dot things dot save it has written this result so there is a write function that happened okay so one document has been inserted if you want to find what is there inside this one DB dot things dot find with brackets there it will give you a specific idea that I was telling earlier that’s called the object ID which is very unique for this format with the value of a B and C respectively so you have a document in the collection let’s say you want to insert another document okay so the way to do it is DB dot things dot save again and here you have a 3 B 4 and C 6 and B as it’s a 200 ok now another result is also inserted now if I do DB dot things dot fine it will show you two documents okay so one is this one the first one that you did and the second one that you know so you have two documents in the same collection called things in the database called DB and these have been assigned object IDs which are really unique identifiers and these are indexed what is the meaning of index you index few things so that you can search very very easily if you want

to find the document where a is 1 see in the second document you have a three and the first document you have a one if you want to find out the document where the value of a is one you can just type in a is one okay so it will give you directly this document and so it’s very very quick it’s already indexed so you can see in this object you have a as one okay you can also add more documents like DB dot things dot save let’s do a different format now okay a is a is 1 B is one and I have a fruit with an array okay arrays should be always with square brackets and you enclose it with an orange and apple appear ok you close it with a square bracket and this one curly bracket okay so if you enter this one something missing in the brackets let me check okay so I have re inserted or resaved this collection of things with save by giving some brackets there and then putting the array for fruits which includes oranges and Pearce now if you look at DB dot things not find you will see now that there are three different types of documents you can also use something called DB dot things dot fine pretty well it makes things a little bit prettier and easy to understand so now here you have after I type in this pretty he’d right there with the ID object ID which is very unique with this information of the document and then this is the second document okay so you have totally three documents beginning from one two and three okay so let’s look at Mongo chip you can actually go to this website Mongo chef and download from this three T dot io / Mongo chef once you’re in there then you can download the manga chef install it and then try to connect it let me pull up Mongo ship from my side here okay so this is how it looks and you have to connect it there I’ve already have a existing connection here so if you want to connect there right there if you want to look at the the properties just have a look at it in the Edit you have to enter their some name for your connection and then the server is localhost this is the port number for Mongo and apart from that you don’t have to do anything else the first step that you need to do after downloading Mongo ship is to use this particular screen with localhost direct connection and then save it okay so now I’m going to connect it and so it’s now connected so if I click here you can see that there are two databases local and test the same thing will be you know as well here show DBS okay so local and tests are visible right there and inside the tests database we have the date the things collection which we created at the same time as we referred it now inside this we have the specific information where you have all this information that we entered there and I double-click on things it will open up a new tab here so we just closed there and then in things you can see that there are three documents so this view is really good you can also go to the tree view where you can see the these three documents or the table view in this fashion or the JSON view so you have a1 b1 and so on the shell is right here in intially shell so if you click on this it will open a new tab where you can enter

things that you want so if I say DB dot things dot fine and click on either f5 which will execute the entire script or f6 which will execute only this line I can see information down there so this is the latest manga version it’s connected to localhost two seven zero one seven it’s the port number now if I click on this which is execute statement at the cursor of line two then it is going to give me this information of of the documents that are there so you can also save the scripts that you write here by going to file and then save script and then you can reopen the same script from there you have all the typical crud operations but they are termed in a different fashion here so let me just put a table okay now let’s look at relational in general and then Mongo and then SQL so in relational you have the crud operation which is create read update and delete okay in SQL I’m going to split here and then from there in a scale you have what does it call insert and then you have read select instead of read then you have an update which remains the same and then do it which remains the same also in Mongo however you have insert and instead of select you have find and so update will remain the same instead of delete you will have a remove so these are the crud operations operations comparison so you have I equals to 0 IP less than 3 I equals to I plus 1 you print hello manga will give you the same thing it will be print three times okay now if you have the same equation or the function here but instead of print hello I wanted to print hello plus I okay so I press f6 at the cursor level okay and now you can see it’s printed three times so I have I equals to this one print hello plus I so which will append this I there like 0 1 & 2 for 3 times so please remember the brackets here the double brackets and then inside hello there so the keystrokes are of Emacs type of the editor a control a for beginning of the query control e for the end of the thing so now let’s see what happens if we just type help right so when you type help you get all these items the same things that you get in fact for the terminal also okay and if you type in help keys let’s see what it gives tab completion command is G over the command prompt so start of the line end of the line control K delete at the end of the line that is fine now if you want to try if we can do one more which is for I equals 10 and I less than 10 5 plus plus print I okay because it is the same it is it hasn’t given any information now let’s say I’ll just remove this all these things there if I say X equal to 1 y equal to ABC Z equals 2 you can see how it gives you the information and the

brackets when you as you are typing in okay if I say Z dot ay okay now it will give me the value of 1 there okay so if I now say Z Z or Zed okay which remains the same now if I have w equals to a and I want to Z of W okay it’s it will still give you the 1 so there are different ways of representing one here I just press the f6 because that the line level doesn’t have any meaning so that’s why f5 will give you more mini because it executes all these functions earlier because the dot notation is like a lookup of properties or methods or instance variables within an object when you use the square bracket it looks up data as dictionary with keys and values how does MongoDB represent data in fact represents data using B Sun represents data using V some binary script object notification it is like a nested dictionary so we map the documents to objects in programming language to represent those key value associations in JavaScript the type of object is called JavaScript object so you have your object equals two with curly braces you represent a is 1 B is 1 or let’s say hello and you can have a C which represents an array so an array needs to be defined with a square bracket and then you have your apples and it appears so I’ll close this with a square bracket and this one so this object can be a document so MongoDB uses the binary representation as B Sun it is in fact a short form of binary JSON that’s that’s the beasts on actually so if you go to B’s on spec dot o-r-g and look at elements or data types you can see a number of them beginning from a number integer a number long which would be a 64-bit integer value a number long 1 plus number long 3 you can add those kind of long numbers you can have a date so to construct an object in JavaScript you have to basically say object equal to this one right so it’s important to understand that the binary JSON is a very very flexible form of binary representation for JSON documents okay so you know now how to insert documents so if you are in DB then you would say DB dot test as a test is a collection and then you insert something okay collections are properties of database ok so let’s say now you have let me just clear all so it is cleared the clear will be here so I’ve cleared all the result tabs there now you want to add let’s do another exercise for a different collection now let’s say D or C talk equals two you have your name as let’s say Smith whose age is 30 and whose profession is as a hacker all right now you wanna do insert this into a new collection so I’m going to create a new collection called people as I’m referencing it it will create so when I insert this document there and you click on f5 okay either let me just check once here okay so let’s do another line one so I have to remove there’s an extra brace there so I’m just removing it and then I do an f5 which is executing all

the script it will create a document directly inside this collection called people which is just now created ok so that’s not doing things so you have name age and a profession right that will remain the same start up logs ID fine so you now have created so people is a collection and insert is a method in database DB so insert method puts a document now in order to query a collection you have to say DB dot people it will automatically give you that dot find okay so f6 it will show you the information that is there in that particular document so underscore ID is a primary field with unique value you can’t change the sample score ID okay it said object ID is different from underscore ID so object ID is a global identifier which which is constructed and used as underscore ID R underscore ID is a primary field which cannot be changed right then you go to click on test right click that and then click on refresh all it will show you the new collection that you have added so that’s people with its own underscore and then think so you have now got two collections or two collections inside this test dB you can also change the DB by saying use local and then create new kinds of collections so in people collections you have got a one single document in things collections you have got three different types of documents so we are talking earlier about why is there a need to create more than one collection because in one collection you can have different types of documents and data types and merge them together including areas dictionaries and so on one of the reasons were that I had stated was keeping different kinds of documents in the same collection can be difficult for developers and administrators devs need to make sure that each query is only returning documents of a particular type okay or that the implication code performs a query that can handle documents of different types so it’s difficult to take out documents containing some other information so it’s to make it more simple you have more collections the other reason is that it is much faster to get a list of collections than to extract a list of the types in a collection so let’s say if you had a type which is M United here you had a type feel all right in each document ok that’s specified whether specifies whether a person is slim or obese okay it would be much slower to find these two values in a single collection than to have two separate collections and query the right kind of collection that’s the second reason the third reason is that grouping documents of the same kind together in the same collection allows for data locality okay so you can get several different kinds of information about a person from a collection containing only those only that data that is more likely to have a less or fewer dis Cris disk seek fewer disk seeks and more data locality and therefore more speed right so this is also one of the other reasons that we have multiple collections the other final reason is that you begin to put some structure on your documents when you are creating indexes for the sake of index also you can have multiple collections okay when you have you can have multiple indexes too but this is more true when you have a unique index so this index is a defined per collection so index per collection so by putting only those documents of a single type into a particular collection or in the same collection we can index your our collections more efficiently okay so there are really good reasons for grouping related types of documents together and collections together even though Mongo does not really enforce that kind of a rule a few other things to remember about collection this is not

a valid collection named collection names they should not contain characters like backslash 0 or a null character because this is not proper for a collection name we should also not start start a collection with system okay as prefix this is reserved for internal collections only internal elections only because you may have system dot users which is actually a collection with that contains all the information of the users who are accessing the database or the particular tag kinds of collections in the earlier one also you can have blog dot authors you can have logged or pause there could be absolutely no relationship between these two but you can form sub-collections also their usage is very highly recommended by Mongo community this IntelliJ is also you know it works as a fully featured JavaScript interpreter which is capable of running arbitrary JavaScript programs so if you do any basic math here for example X and then you do an X by 5 and then run this code here it will give you 40 and from this code so I put f5 and it has given 200 here so it’s actually given three different results for me so text and text is again 200 that the final text is 40 so X by 5 is 40 ok so if you do only this one fy6 it will give you the same result here okay so it works as a JavaScript interpreter you can also do many other functions like factorial excite data costate math and so on now which is which are very useful for the real beauty lies in the MongoDB client which is actually a standalone one so on startup earlier you have seen DB and then tests like this under DB and then you have seen the test collection so now what exactly happens is that the shell connects to the date test database so the test is the database on a MongoDB server and assigns this database connection to the global DB variable and this DB variable is the primary access point to your MongoDB server through the shell this shell itself will contain some add-ons and these add-ons do not provide any extra functionality but they’re nice to work at for instance one of the most important operations is selecting which database to use so if you want change the database you would say here in this case you have two databases local and tester right so if you say use local then your the next operations will be done inside this local database okay all kinds of collections can be accessed by entering DB dot and then the collection name this returns the co l collection in this particular database and that is local if you look at the data types that are there in MongoDB there are six basic data types that actually belong to the JSON family so documents in MongoDB are more like JSON the JavaScript object notification very similar to objects in JavaScript so the six data types that JSON provides is a null boolean numeric string array and object and null can be used to represent both a null value as well as a non-existent field so for example you may write it in this fashion which is the value of x can be null okay and then you have a boolean which is a true or false and the shell defaults to floating numbers so therefore these numbers look normal in the shell you may write x assign to 3.14 X – 3 string is again any string of utf-8 characters it can be represented using the string type dates

are from Mongo they are stored as milliseconds and the timezone is not shared it’s not stored actually so that the way you write the date should always be like like this which is X and the new data you do not write just date but the new date and that’s the idea reg X is the regular expression that queries can use regular expressions using the syntax of the same array it comes again from JavaScript it sets or lists of values every document document within a document so you can have documents that contain entire set of documents embedded as values in the has a parent-child relationship object ID is a 12 by tidy for your documents and your binary data is a string of arbitrary bytes it can be manipulated from the shell also and then the chord which is the queries in documents can also contain some arbitrary JavaScript code these are few types that are mostly used internally and remember to have the date always has new date rather than just the date like I have written here so that new construction is absolutely important that is we have seen a few earlier embedded documents so here when you have an embedded document your document becomes the value ok for a key so in this case it’s called the embedded document I used to organize data and more than a flat structure of key value pairs so embedded documents will look something in this fashion where you have info which are created as a document equals to so on the name is John Doe address Street in this one so the address here is itself a document that is embedded in this particular document okay so the address itself has got these braces curly braces with 123 park street in town in New York and that’s there within the info so there is one document embedded here is if you run a 5 it will tell you that first of all it’s a document and that it represents this particular format so underscore ID and object IDs these are again two different kinds of data types that are there in Mongo every document that is stored in Mongo must have an underscore ID this ID key can be of any type but it defaults to an object ID so in a single collection every document must have a unique value for underscore ID so this basically makes sure that every document in the collection can be uniquely identified so if you look at this things collection where you have three documents each ID has got a different value and this actually represents these these documents these three documents individually and uniquely and neither collection could contain more than one document with the same same ID it has to be completely different and then you have this object ID that’s the default type for underscore ID it is a very unique way to do to recognize globally across different machines and it is very different as opposed to auto incrementing primary key which is quite difficult and time-consuming so it rests on the fact that MongoDB is designed to be a distributed database so it was important to generate such unique identifiers in a distributed environment so object IDs they use 12 bytes of storage which effectively gives a string representation that is 24 hexadecimal digits two digits for each type so the first four are for the timestamp the next three are for the machine which is the unique machine from where this idea was created this is the process ID the next two and the last three are incremental values so look at this extra decimal digits this is actually a 24 bytes this one this is really four bytes this is also 24 bags the last three are incremental to e3 and to you for for array it is slightly varying so in this format the 12 bytes of storage are actually generated even though an object

ID is represented as a giant hexadecimal string the string actually is twice as long as the data being stored so you have an insert and you also have a remove if you use remove then it deletes all the documents in a particular collection so let’s say you want to see what direct documents are there in this feeble collection then you want to delete it all right so we go to the intially shell and then we would say let’s clear this off first and then DB dot people okay it’s already giving us their dot remove okay we’ll close it and then run it with f6 okay so the error says error removed needs a query okay so you have to put two braces here inside which is actually a blank there and then when you run it from here then you would see that the the document is as removed okay if I try to see it there is no document so DB dot people dot remove will remove all the documents in this people collection if it give you the error no query found or if you need to provide a query then you have to work with the the color braces there or also remember that this doesn’t actually remove the collections of the collection stays as it is and any metadata information about this collection will still exist the remove functional optionally takes a query document as a parameter or when that kind of a query is given then only those documents which match such criteria which is given here inside the the query only will be removed once the data is removed okay so there’s nothing here once it is remove it is gone forever there is no way to remove or cancel they remove or recover the deleted documents once you do it it is it is gone now when you use something like this DB dot people dot drop in this case the entire collection is dropped of there which is basically and all its metadata information is is definitely removed okay so this is very important now this true and therefore if you go to test and refresh all you will see only things there is no people collection in this in insert a document and also updated document so an insert document will have the format like DB dot collection.com rod collection dot insert so not TOCOM insert and then you have your document name okay so this is your collection name which were you have here and then you insert that particular document let’s clear this up and let me write it a new one so a DB dot so I’ll use some post as a collection in this and then I would say insert now I’m going to insert multiple documents in this so the way you want to create it is insert and square brackets okay so let’s try a new one for using the the insert and the update there okay so let’s do a new collection called post I’ve just included that one okay and let’s insert let’s say the title that we have currently is Luongo DB and description Mongo is no SQL DB a comma by in telepath okay curly braces call my

let’s do another document here continuously which is this is going to be title which is no SQL DB description Norris QL is schema-less again buy into the path ok so let’s say you got some likes for this and maybe you got some comments also but let’s see so you have some comments this user from Frank his message is very interested okay and now let’s close it okay so you’ll identify where which bracket is getting closed by this one so you have this mention and if you put it there it will show you all those things okay so now let’s do an f5 okay so it is inserted let’s see what is then this DV dot post dot find and the closest I am doing only a f6 so here I’ve got two documents okay one is this with the MongoDB overview and then the second one is no SQL database now we have inserted two documents in this collection called test so ctrl R will show you the post if I want to add or update this particular title then you can use the update functionality okay the way you do it is so let me just go to the next few lines so you do a DV dot post dot update and then you use the title which title you want to change and that is this one right there MongoDB overview will use single quotes or double quotes is all the same so you want to change this close the brackets but in order to help Mongo do that you need to sit okay and set this title to what do you want it to be so now I want it to be Mongo DB for developers so I close this this is done and another bracket there to close it and in addition to this what you have to mention is if you want it to be done in multiple places let’s say there are some more documents okay which have the same title and you won’t change everywhere where the document title is going to be overview – Mongo DB for developers you use something called multi documents to be set as true and then you close it but since we don’t have it right now we can as well close it with with this one there okay now let’s run the this particular thing by saying f6 so right result matched one yeah upsetted zero and modified is one we’ll look it upsetted little later if you do the same thing there what you have done just now for DB find and do an f6 you will see that it is title is changed from huambo DB overview this one to Mongo DB for developers okay so if you want to do a multi document change our update you can use multi as as true parameter there we have now seen the installation of MongoDB on Windows and I’m also explained on how to do it on Linux and also the Mac systems okay guys a quick info if you want to do an end-to-end training on MongoDB in telepods provides a complete certification training on MongoDB on those details are available in the description ok guys we’ve come to the end of this session

I hope this session on MongoDB was helpful and informative for you if you have any queries regarding this session please leave a comment below and be loud to help you out thank you yeah