1 00:00:02,310 --> 00:00:09,510 So now that it's clear that we are free to define a schema for our documents and to structure them in 2 00:00:09,510 --> 00:00:15,540 exactly the way we want them to be structured for our use case or application, let's have a look at the 3 00:00:15,540 --> 00:00:17,660 different data types we can use in mongodb, 4 00:00:17,670 --> 00:00:22,790 so basically the types of data we can save in our fields, in our documents. 5 00:00:22,920 --> 00:00:31,500 There we for example have text, we already saw text data types in this course, text always uses quotation 6 00:00:31,500 --> 00:00:33,930 marks around the value and important here, 7 00:00:33,930 --> 00:00:40,260 I'm talking about the values so the part on the right side of the colon in your json documents. So 8 00:00:40,260 --> 00:00:42,530 you can save text like names, 9 00:00:42,630 --> 00:00:44,720 you also got no hard limitation here, 10 00:00:44,730 --> 00:00:50,940 the only limitation you have regarding the maximum amount of characters in your text are the 16mb 11 00:00:51,000 --> 00:00:54,040 overall size for the whole document, 12 00:00:54,060 --> 00:00:59,520 if your text is greater than that, well then your document becomes too big and your text is too long. 13 00:00:59,940 --> 00:01:03,640 We also have booleans, booleans are simple values, 14 00:01:03,660 --> 00:01:08,850 true or false, is something the case or not, is a user or an administrator or not, 15 00:01:08,850 --> 00:01:15,250 you could save that as a true or false value and that value is called a boolean. Another core data 16 00:01:15,250 --> 00:01:16,050 type 17 00:01:16,060 --> 00:01:17,890 are numbers of course 18 00:01:17,890 --> 00:01:25,350 and actually, we got a couple of different numbers in mongodb, we got integers for example and you see 19 00:01:25,350 --> 00:01:32,730 int32 here because mongodb knows different kinds of integers, int32 integers are integers 20 00:01:32,740 --> 00:01:34,680 that are 32bits long 21 00:01:34,840 --> 00:01:40,840 and therefore if you try to store values that are longer than that, they will overflow that range and 22 00:01:40,840 --> 00:01:44,570 you will end up with a different number, for longer numbers, 23 00:01:44,800 --> 00:01:52,600 mongodb has a solution though, a long number, an int64 integer which you can also assign to store values. 24 00:01:53,260 --> 00:01:57,100 In the shell by the way if you just enter a normal value, 25 00:01:57,100 --> 00:01:59,170 it is treated as a float value, 26 00:01:59,200 --> 00:02:04,690 that is because the normal shell as we use it in the course is based on javascript and javascript doesn't 27 00:02:04,690 --> 00:02:07,670 differentiate between integers and floating point values, 28 00:02:07,720 --> 00:02:09,790 so values with a decimal place, 29 00:02:09,830 --> 00:02:14,870 therefore everything will be stored as a 64bit float value in the shell, 30 00:02:14,890 --> 00:02:19,860 that is the default value and we'll play around with that a bit and see more of that in the numbers 31 00:02:19,870 --> 00:02:21,340 module of this course 32 00:02:21,340 --> 00:02:26,840 but be aware that mongodb is able to store smaller integers and bigger integers, 33 00:02:26,920 --> 00:02:31,960 the solution you choose here of course kind of defines how much space will be allocated and therefore 34 00:02:31,960 --> 00:02:39,030 how much space will be eaten up. And you also can store decimal numbers so numbers with decimal places, 35 00:02:39,280 --> 00:02:44,660 I already said that the default in the shell is to store a floating point value, 36 00:02:44,830 --> 00:02:52,270 you also got a special type, number decimal and that is provided by mongodb to store high precision 37 00:02:52,300 --> 00:02:59,110 floating point values because normal floating point values also called doubles are basically rounded, 38 00:02:59,140 --> 00:03:02,690 so they're not super precise after their decimal place. 39 00:03:02,830 --> 00:03:09,120 For a lot of use cases, it's enough though, like for prices in a shop, you got enough precision for that 40 00:03:09,190 --> 00:03:15,460 but if you're doing scientific calculations or anything like that, you might need a very high precision 41 00:03:15,550 --> 00:03:22,750 and there is a special type that offers this, a very high decimal place precision where you got 34 42 00:03:22,870 --> 00:03:23,880 decimal places, 43 00:03:23,920 --> 00:03:30,370 so after the comma which are not rounded but guaranteed to be correct and precise. It's simply a computing 44 00:03:30,370 --> 00:03:34,150 limitation that we got no 100% precision all the time 45 00:03:34,210 --> 00:03:41,120 but that rounding occurs. Now besides these basic values even though some number values here already 46 00:03:41,120 --> 00:03:48,980 are a bit more advanced, we also got the objectId value, the objectId object is a special object automatically 47 00:03:48,980 --> 00:03:57,020 generated by mongodb to give you a unique ID which is not just a unique random string but also a string 48 00:03:57,020 --> 00:04:03,920 that contains a temporal component, so that if you create two elements after each other, two documents after 49 00:04:03,920 --> 00:04:11,540 each other, you are guaranteed to have the right order due to that ID because the older element will 50 00:04:11,540 --> 00:04:14,490 have an ID that comes prior to the other one, 51 00:04:14,660 --> 00:04:21,460 so there is this sorting built into the objectId because it respects a timestamp. 52 00:04:21,500 --> 00:04:29,120 Speaking of timestamps, you can also save a date in your database, there is a special ISO date type which 53 00:04:29,120 --> 00:04:34,280 you can well use, you can construct the date and save that to your database 54 00:04:34,340 --> 00:04:40,650 and that is then a date which you can work with to do a date calculations and so on. 55 00:04:40,760 --> 00:04:45,810 And there also is a timestamp type, the timestamp is mostly used internally, 56 00:04:45,830 --> 00:04:52,010 you can create it automatically, mostly you let mongodb create that for you and that is guaranteed 57 00:04:52,010 --> 00:04:53,030 to be unique too, 58 00:04:53,030 --> 00:04:58,610 so even if you create two documents at the same time, they will not have exactly the same timestamp 59 00:04:58,850 --> 00:05:01,680 because it will basically take into account the current time 60 00:05:01,730 --> 00:05:09,110 and then also add an ordinal value, so that two documents at the same time still don't get the same time 61 00:05:09,110 --> 00:05:15,040 stamp but respect the order in which the insert command was issued for example. 62 00:05:15,080 --> 00:05:21,000 So you got that timestamp too and you could say that object, that the kind of is based on that timestamp 63 00:05:21,050 --> 00:05:26,430 and then just uses some algorithm to spit out a seemingly random string. 64 00:05:26,510 --> 00:05:30,290 Last but not least, you saw that you can embed other documents, 65 00:05:30,290 --> 00:05:36,860 that's of course important too, you can embed documents and these documents can then in turn embed other documents 66 00:05:36,890 --> 00:05:40,210 or hold any fields with any of the values you see here 67 00:05:40,460 --> 00:05:46,520 and you can also have arrays as values and the arrays are simply lists of values, 68 00:05:46,520 --> 00:05:52,820 you can have a list of strings, a list of booleans, a list of numbers or a list of other embedded documents 69 00:05:52,880 --> 00:05:56,880 or even a list of lists, a list of arrays, that is possible too. 70 00:05:57,200 --> 00:06:00,770 So these are the data types and throughout the course, you will see them again, 71 00:06:00,770 --> 00:06:02,480 so we'll work with them 72 00:06:02,510 --> 00:06:07,610 and for example there will be a whole module where I will work with numbers to give you a feeling for 73 00:06:07,820 --> 00:06:11,770 why we have these different types of numbers. In the next lectures, 74 00:06:11,780 --> 00:06:17,450 I just want to play around with these types a bit and give you a feeling for how we create the more 75 00:06:17,450 --> 00:06:21,190 advanced types like dates here and how we can save them and work with them.