MongoDB in 18 Minutes - Intro to MongoDB

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey everyone it is Caleb from Caleb's video maker - and this is your introduction to MongoDB now MongoDB is a non structured database and essentially what that means is the data is not constricted to the shape of a table and I'm going to go over all of that and this video is it's going to be an introduction on what structured versus non structured means and also how to use MongoDB so we'll actually have some stuff on the computer MongoDB is becoming extremely popular because of its speed ease of use and scalability I also wanted to share with you some tools that can make your MongoDB experience a lot easier that tool that I want to share with you is called cluster control and it is a database management system that allows you to easily scale setup and work with MongoDB that software system is made by a company several nines which has decided to sponsor this video which is sweet so if you guys want to support my channel go look at their stuff cluster control and several nines and give it a try with MongoDB so here on Caleb the video maker - I have done hundreds of videos on databases but nearly almost every single one has been on structured databases another name for them is relational database and when we are talking to a relational database we use what's known as SQL for structured query language notice the s4 structures but when we're talking about a non structured database these are often classified as no SQL meaning not only SQL if you've had any experience with databases you may have heard of MySQL VB to Oracle sequel server those are all fundamentally different when it comes to the way you structure your data now some of those databases do support non structured data but MongoDB is designed for non structured data but if we had to summarize it you can think of relational databases as structuring data in tables so a table just has a series of columns which define the structure of our data so if we have a table we might have three columns for example we could have a user table and we can have a first name a last name and a email and every single row or entry into this table has to follow this structure so we could have one in here like this and that's great and all but this can be an issue if for some reason we want to add an extra column but only for certain rows when we're talking about a value for a certain column we often call that a field so if we want to add a field to this row for example a birthday you can see that it doesn't quite fit this table structure and it would only really make sense if we added a column and now the row follows the table structure structured databases aren't necessarily bad they're a great thing in fact non structured data you should consider it as an addition to your structured data consider it to be augmenting your development experience but the problem is structuring data can sometimes be hard if we don't have a continual structure of what the data looks like and even if the data is always the same structure database design can be very challenging so I have a series here on YouTube database design and the sole purpose of this series is to teach you guys how to structure tables and connect tables inside of a relational database well a lot of this concept goes away when we're talking about non structured data now not all database design is going out the window there's still stuff you have to consider and you can still have relationships between data but things become a lot easier when you no longer have to worry about whether your data is going to fit perfectly inside of a table instead we have these things called collections so a collection correlates to what a structured table is but it's a little different so we can put what we call documents in this collection so a document is just one entry inside what would be a table but it's actually a collection so for example we could take this whole thing and throw that in a document and put that inside of a user's collections that works perfectly but we can actually make another document with different data or slightly different structured data and we can also put that inside of that collection it's not restricted just to documents that fit that specific format when we are working with these documents the way we represent data is a little bit different actually it's completely different but once you get used to it it's not that bad I'm going to clear some of this off so I can write down how to represent data but in a document rather than in a table this is the same exact table that was down here I just screwed it up and now I have a little bit more room and everything's just a little bit cleaner we can see that we have one row if we wanted to add another row we could just right below it there is our second row and you can see it follows the exact same structure as the first row now if we weren't working with a structured database and we are working with a non structured database such as MongoDB and we didn't have this table structure how do we go about representing this data well that is where the document comes in as I mentioned earlier so the document is the same thing as the row but a little bit different because it doesn't have to follow the same structure as the table columns and inside of this document you're going to have key value pairs where the key is the field or attribute and the value is whatever that value is so for example the key for here is first-name the value is Caleb so what we would do is type out first name colon and then inside a close Caleb so what we're going to do is just have a field and a value for every single column if you want to call it that until we run out of data for this specific instance of the user so if this is a user table this might be inside of a user collection now all of these fields are going to go inside of these little curly braces and once we have all that we have one document and that can go inside of the collection these documents are dynamic though because they don't follow a structure that means I can add any field here that I want and give it a value we could add this one to the collection too and that's not going to break anything because the collection doesn't have a strict formula of what the data has to look like what we have so far here is just a very simple document they can actually get pretty complex don't worry about all of the complexity right now because the important thing is to understand what non structured data looks like how to put that in a database and how to get that data back out so that is the goal of this video I'm going to take something that looks similar to this put it inside of a collection and then get that data back out by selecting it or querying that collection and trying to get this document now that you got the introduction to non structured data I want to teach you how to install MongoDB and start working with a database so by the end of this video hopefully you've got the very basics of how to work with MongoDB the very first thing I want to show you guys is how to download MongoDB super simple just go to the Google's search MongoDB and find the link for the most recent version then click try it now then click community server scroll down and download once you've got that downloaded you can extract that wherever you want and you'll get a folder that looks like this the folder that interests me most is this bin folder and there's two specific files D and now D is the actual server and then is how we talk to that server and we'll see how to use both of those in just a moment but first I want you to go to the root directory now you can do that by clicking this go up here and going to folder and then just typing a forward slash now inside of here we need to create a folder the reason I'm making you do all this is because the database actually has a prerequisite folder that needs to be created so in here right-click and click new folder and then we'll just name that data go in that folder and actually create another folder inside and we will name this DB all right so we got the folders we need we can now go back to the original files now we are ready to start working with these files so right-click D and click open and you can see that it says waiting for connection yada yada yada that means it's running the next thing we need to do is open alright this is actually what we're going to be using so I'm going to make this a lot bigger alright so we got everything we need set up for the rest of this video so we are ready to start working with MongoDB so to begin let's clear the screen using CLS that way we just have a clean working area now the way works is pretty interesting if you try to work with something that doesn't yet exist will actually create it for you to give you an example if we try to work with a database that doesn't exist it will just create it let's try it we can say something like use and then you know give it a good quality database name and it says switch to DB subscribed but I mean who knows this subscribe even exists it just makes it for us it works the same way with collections which if you remember collections are what store all of our documents or our what would be the equivalent of rows and the collection would be the table so we can just start working with a collection as if it exists and will create it for us that means we can just skip creating a collection and start talking about inserting data into that collection it's kind of weird because I feel like I'm skipping like you know big substantial parts but it works so let's insert some data into our imaginary collection right now the way you do that is by typing DB dot and then you put the collection name so we can name it whatever we want let's say users for example and then we can use a function and there are a couple different functions but the one I'm going to use is called insert one and then you put parentheses now inside of these parentheses is where you put your data now just so you guys know it's basically impossible to type inside of a terminal so I'm actually going to delete this and type it in a text editor and then copy it and paste it over so I'm just going to use my high quality IDE here so let's do that again DB users dot insert one and now let's put some data in here the very first thing you always want to start with are the curly braces your document gets encapsulated inside of curly braces now we can start naming the fields so name and then we'll give it a value and let's give it another field and we can extend this as much as we want and in fact you can even do more complex things for example you can put arrays in here so to make an array you use square brackets and then all of your data is in here like this so you can see Aimee is actually an editor and a manager now this is interesting because this is valid inside a MongoDB but if we were working with structured data this would be kind of interesting I'm not sure if it would work some databases have some types of data types that allow you to give multiple values such as a set but not all databases support sets and sometimes it's frowned upon and you should actually take this data extract it into its own table and make a relationship so you can see that the complexity of relational databases is much more when you're working with non structured relational databases or no sequel databases you can just kind of nest things inside of your document so let's take all this and go over to the terminal and paste alright now it returns something to us and it says it has an object ID so this is the equivalent of what would be a primary key but we didn't have to set that up it did that all for us and that is how you uniquely identify this document so let's talk about querying our data so querying our data is asking the database to give us our data back to us in a relational system you would use a select state but it's a little bit different with MongoDB so I'm going to go back over to the notes and type out how to do that first you say DB and then you say the collection name just like the previous command and then you use the function find this here is the equivalent of select star from users inside of a relational system essentially it's going to return all of the documents inside of the users collection so we'll copy this come over here and paste it and there you go and you can see it actually includes the ID with this and it added that for us but now you know that it's actually there inside of the document now if we had more data inside of our collection it would return all of that data so for example if I put another insert statement and this time just to show you guys something cool that you can actually add your own fields which is really cool thing about non structured data then we'll get that data back out and see that it's different so let's go in here and add an email okay so we gave that field to this person and also you know I'm just going to change this up just a little bit so you can kind of see the difference yeah give her a different name and you know change your age all right let's insert this all right now let's query our data and you can see a returned both of them and one of them has an email what the other one does not now you can actually do more complex things like you know you might not just want to select everything especially if you have millions of documents so we can actually specify some rules of what kind of data we want to return so let's go back over to our notes if we were doing this in a relational system it would be known as a where clause so you'd say like hey give me everything where the email is Amy I'd email comm with non structured data it works a little different but same concept so it's going to look like this DB users don't find inside of these parentheses is where we can be more specific of the data we want to return so for example we could say hey we want the person's name to be Amy and anybody who does not have the name me we don't care about right now so let's copy that go over here and paste it and you can see it just returned the person with the name Amy you can definitely do more complex things if you really want to for example you could say oh I want to get anybody with the age less than 50 for example but I'm not going to get into all those details because I just wanted to give you guys a rough introduction and lastly before I go I wanted to briefly show you the cluster control tool that I was talking about that's available on several 9s comm this tool kind of breaks up databases into four steps deploy manage monitor and scale and the tool is designed to help you do all four of these things seamlessly but the cool part is is that you can actually integrate with other databases including MySQL and Postgres give cluster control a try and let me know how you guys like it that's all I got for the introduction and now back to the real world so I can give you the conclusion to close this video I wanted to remind you guys that non structured data is not meant to be a replacement for structured data at least not yet but it is important to know that the way the world works with data is changing so if you're not getting on board with this non structured data and at least understanding it within a couple years you could be severely behind I think it's really important to understand non structured data because the flexibility of it is great if your business needs or the way your data looks in the future changes you don't have to go back and change all of your infrastructure which can be extremely time-consuming and expensive so if you're into programming I would highly recommend given MongoDB a try try writing an app to connect to a MongoDB then try writing an app to connect to a MongoDB database and if you're more on the business side where you're trying to run a technology company at least know the basics of MongoDB so if the situation comes up where you think hmm nah unstructured data would be useful you actually you understand what that means and you can apply that then so thank you guys for watching I know I didn't get in a whole lot but hopefully now you're a little bit more prepared for the world of non structured data if you would like to see more and learn more I think a video series would be more fit for that so if you would like that please leave a comment below and I'll see what we can do so thanks guys please be sure to subscribe and I'll see you in the next video
Info
Channel: Caleb Curry
Views: 296,261
Rating: 4.8802481 out of 5
Keywords: MongoDB, intro to mongodb, introduction to mongodb, mongodb tutorial, tutorial, mongo, db, nosql, calebcurry, calebthevideomaker2, caleb, curry, database, mongo db tutorial, mongo tutorial
Id: bKjH8WhSu_E
Channel Id: undefined
Length: 17min 42sec (1062 seconds)
Published: Fri Aug 04 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.