1 00:00:02,590 --> 00:00:08,270 So let's play around with that a bit and let's start with the int 32 cue why we might want to use 2 00:00:08,260 --> 00:00:08,980 that. 3 00:00:08,980 --> 00:00:15,730 So let's say we have a collection in our database, the persons collection and there, we insert one person. 4 00:00:16,180 --> 00:00:20,430 Now that person might have a name, Max and might have an age. 5 00:00:20,530 --> 00:00:26,190 Now thus far, I always store the person like this and now generally, there's nothing wrong about that. 6 00:00:26,320 --> 00:00:36,440 If I now retrieve my person here by finding it with find one and I get my collection name right here, 7 00:00:37,190 --> 00:00:44,360 I see that the age seems to be stored like this and that is the case because it's a 64 bit float or 8 00:00:44,360 --> 00:00:47,040 double and therefore here, 9 00:00:47,150 --> 00:00:52,830 the path, the integer path is actually stored with full precision, just the decimal part is not. 10 00:00:52,850 --> 00:00:57,500 And actually even though we don't see it here because in the shell which is based on Javascript, it's 11 00:00:57,560 --> 00:01:04,310 automatically kind of output as a integer, even though we don't see it here decimal places are stored 12 00:01:04,310 --> 00:01:05,490 for this number too 13 00:01:05,600 --> 00:01:10,550 and behind the scenes this will be stored as something like this, something like that and there 14 00:01:10,550 --> 00:01:12,940 will be some imprecision at some point. 15 00:01:13,070 --> 00:01:16,060 So this too here at the end which I just came up with 16 00:01:16,130 --> 00:01:20,480 but we'll have something like this in there, we can't see it here but this is actually how it's stored 17 00:01:20,490 --> 00:01:21,430 behind the scenes. 18 00:01:21,500 --> 00:01:22,630 And that is fine here, 19 00:01:22,640 --> 00:01:26,490 we just use the age in our app, we would always use it as an integer let's say, 20 00:01:26,540 --> 00:01:32,910 so we don't care about some imprecision here but it's worth noting that we'll have that imprecision. 21 00:01:32,960 --> 00:01:38,780 It's also worth noting that if I now have a look at the stats of my persons collection, I get loads 22 00:01:38,780 --> 00:01:39,460 of data here 23 00:01:39,500 --> 00:01:45,140 but if we scroll all the way to the top, we'll see that we have a size of 49 and that size is simply 24 00:01:45,140 --> 00:01:51,280 there because we have one entry and that one entry has a name and has an age. 25 00:01:51,350 --> 00:01:54,830 Now I showed this earlier in the course but it's really important. 26 00:01:55,010 --> 00:02:00,310 Let me quickly delete all entries here in this collection 27 00:02:02,160 --> 00:02:08,120 and let me add a person again with insert one and this time, I'll only add the age so that we really 28 00:02:08,120 --> 00:02:10,810 only can focus on the number here, so 29 00:02:11,720 --> 00:02:14,350 age 29. 30 00:02:14,620 --> 00:02:18,010 If I do that and I now have a look at the stats again and 31 00:02:18,010 --> 00:02:19,630 we scroll all the way to the top, 32 00:02:19,630 --> 00:02:23,840 we see a value we saw earlier in the course too, size 35, 33 00:02:23,860 --> 00:02:28,400 so this is the size of this one entry in our database. 34 00:02:28,410 --> 00:02:32,140 Now let's use an int 32 and we can use that, 35 00:02:32,140 --> 00:02:40,790 first of all I need to delete all entries, we can use that by using number int as a wrapper around 29. 36 00:02:40,810 --> 00:02:46,060 Now important, you can pass number int like this or in quotation marks, 37 00:02:46,360 --> 00:02:48,490 so this is also possible. 38 00:02:48,820 --> 00:02:55,900 If I enter my integer like this and I now have a look at the stats and I scroll all the way to the 39 00:02:55,900 --> 00:02:59,350 top, we see it's actually a bit smaller 40 00:02:59,470 --> 00:03:04,720 and that is one reason why it might be worth considering using that integer 32, 41 00:03:04,730 --> 00:03:10,360 so this number int constructor here and important, number int is what we use here in the shell to create 42 00:03:10,360 --> 00:03:12,590 such an int 32 value. 43 00:03:12,700 --> 00:03:18,340 If you using a mongodb driver in your application, you'll have to use a method provided or a type 44 00:03:18,430 --> 00:03:20,160 provided by that driver 45 00:03:20,260 --> 00:03:24,400 and it also depends on the programming language you're working in because you might be working in a 46 00:03:24,400 --> 00:03:30,940 programming language which unlike javascript does not use a 64 bit float as a default value 47 00:03:30,940 --> 00:03:34,990 but let's say which does use a 32 bit integer as a default value, 48 00:03:34,990 --> 00:03:41,140 so the documentation of your mongodb driver is then the way to go to find out how to create that 49 00:03:41,170 --> 00:03:47,560 integer there but you will find it in there easily and in the from shell to driver module towards the 50 00:03:47,560 --> 00:03:54,130 end of the course, I will also dive into some example driver docs and show you how we could create an 51 00:03:54,130 --> 00:03:57,810 integer there. And actually just to show what I mean, 52 00:03:57,850 --> 00:04:03,730 here's a quick example from Stack Overflow where you see some dummy code or some demo code on how you 53 00:04:03,730 --> 00:04:08,850 would create an int 64 in python with the mongodb driver, so this is using the official mongodb 54 00:04:08,850 --> 00:04:09,780 driver 55 00:04:09,880 --> 00:04:14,800 and there you see essentially you just import something from the mongodb driver, 56 00:04:14,800 --> 00:04:19,500 so this is part of the mongodb driver or of the dependencies it ships with and you have this 57 00:04:19,540 --> 00:04:25,930 int 64 constructor essentially which you use to then create a number that is too big for a normal integer. 58 00:04:26,410 --> 00:04:33,400 And for int 32, we don't really have that here because in Python, an integer will by default be stored 59 00:04:33,490 --> 00:04:36,400 as an int 32 in mongodb and that is what I meant, 60 00:04:36,400 --> 00:04:38,800 it depends on the programming language you're working 61 00:04:38,890 --> 00:04:40,090 and then on the driver 62 00:04:40,150 --> 00:04:45,310 but in general, what I show you here with number int or number long as we will then also use it, 63 00:04:45,380 --> 00:04:47,590 this will also work in your drivers, it 64 00:04:47,650 --> 00:04:53,010 then just simply depends on the language and what the default values there are. Here in the shell, 65 00:04:53,020 --> 00:05:00,160 it's based on Javascript, therefore the default is the 64 bit double and therefore we can force integer 66 00:05:00,220 --> 00:05:04,540 value with number int wrapping our value. 67 00:05:04,630 --> 00:05:09,950 And we would do this because we save some space, it's a bit smaller which of course is not too bad 68 00:05:10,060 --> 00:05:15,520 and if we don't need the decimal places, we can of course also simply get rid of them.