So let's play around with that a bit and let's start with the int 32 cue why we might want to use
that.
So let's say we have a collection in our database, the persons collection and there, we insert one person.
Now that person might have a name, Max and might have an age.
Now thus far, I always store the person like this and now generally, there's nothing wrong about that.
If I now retrieve my person here by finding it with find one and I get my collection name right here,
I see that the age seems to be stored like this and that is the case because it's a 64 bit float or
double and therefore here,
the path, the integer path is actually stored with full precision, just the decimal part is not.
And actually even though we don't see it here because in the shell which is based on Javascript, it's
automatically kind of output as a integer, even though we don't see it here decimal places are stored
for this number too
and behind the scenes this will be stored as something like this, something like that and there
will be some imprecision at some point.
So this too here at the end which I just came up with
but we'll have something like this in there, we can't see it here but this is actually how it's stored
behind the scenes.
And that is fine here,
we just use the age in our app, we would always use it as an integer let's say,
so we don't care about some imprecision here but it's worth noting that we'll have that imprecision.
It's also worth noting that if I now have a look at the stats of my persons collection, I get loads
of data here
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
there because we have one entry and that one entry has a name and has an age.
Now I showed this earlier in the course but it's really important.
Let me quickly delete all entries here in this collection
and let me add a person again with insert one and this time, I'll only add the age so that we really
only can focus on the number here, so
age 29.
If I do that and I now have a look at the stats again and
we scroll all the way to the top,
we see a value we saw earlier in the course too, size 35,
so this is the size of this one entry in our database.
Now let's use an int 32 and we can use that,
first of all I need to delete all entries, we can use that by using number int as a wrapper around 29.
Now important, you can pass number int like this or in quotation marks,
so this is also possible.
If I enter my integer like this and I now have a look at the stats and I scroll all the way to the
top, we see it's actually a bit smaller
and that is one reason why it might be worth considering using that integer 32,
so this number int constructor here and important, number int is what we use here in the shell to create
such an int 32 value.
If you using a mongodb driver in your application, you'll have to use a method provided or a type
provided by that driver
and it also depends on the programming language you're working in because you might be working in a
programming language which unlike javascript does not use a 64 bit float as a default value
but let's say which does use a 32 bit integer as a default value,
so the documentation of your mongodb driver is then the way to go to find out how to create that
integer there but you will find it in there easily and in the from shell to driver module towards the
end of the course, I will also dive into some example driver docs and show you how we could create an
integer there. And actually just to show what I mean,
here's a quick example from Stack Overflow where you see some dummy code or some demo code on how you
would create an int 64 in python with the mongodb driver, so this is using the official mongodb
driver
and there you see essentially you just import something from the mongodb driver,
so this is part of the mongodb driver or of the dependencies it ships with and you have this
int 64 constructor essentially which you use to then create a number that is too big for a normal integer.
And for int 32, we don't really have that here because in Python, an integer will by default be stored
as an int 32 in mongodb and that is what I meant,
it depends on the programming language you're working
and then on the driver
but in general, what I show you here with number int or number long as we will then also use it,
this will also work in your drivers, it
then just simply depends on the language and what the default values there are. Here in the shell,
it's based on Javascript, therefore the default is the 64 bit double and therefore we can force integer
value with number int wrapping our value.
And we would do this because we save some space, it's a bit smaller which of course is not too bad
and if we don't need the decimal places, we can of course also simply get rid of them.