Now before exploring all these exciting types you saw in the previous slide, there is something important
I need to highlight about numbers in the mongo shell.
The mongo shell is based on Javascript, it's basically implemented in javascript
you could say and therefore it follows some default javascript just has well inherit and one of that
is that a number like 64 by default in javascript is not stored as an integer or treated as an integer
but as a 64 bit float,
so as a double. This is just a default in Javascript,
so this number and this number are essentially the same in Javascript, behind the scenes they will be
stored in something like this, with some kind of imprecision at some point, doesn't have to be a two
at exactly this place but it will have some imprecision because it's a 64 bit float.
This is how it works in javascript and therefore, if I just use a dummy collection, num test, whatever
you want to use and then insert one value in there with A1,
since I'm doing this from within the mongo shell, this one will be inserted into mongodb as a double
not as this 128 bit high precision decimal,
we'll have a look at that in this module
but as a 64 bit float double.
So this is how it will be inserted,
it will not be inserted as an int 32 and I highlight this because this is really just inherent to the mongo
shell because it's based on Javascript, you would face the exact same behavior when working with nodejs
in the mongo driver there
but for other languages and their drivers, let's say for python, this will differ. In Python, a value like
this would be an integer and a value like this would be a float,
so python does differentiate and therefore there, this would be inserted as a double into mongodb,
so will be stored as a normal double in the database,
this would be inserted as an int 32
and this will be important to understand.
Now I will later in the from shell to driver module show you how to write code with a
mongodb driver in a real application and I will show you how you can get a feeling for what is
supported,
which types do I have to convert
but you also always have to know the language you're working in and you have to know the defaults for
this language. Does it differentiate between integers and doubles?
If yes, what is the default integer,
is it an int 32
and then you will know do I need to convert it as we will do it in this module
because for the shell which is based in javascript, we will have to explicitly create an int 32 because
this is not one as I just explained, for other languages this will not be required
and this is just one important thing you have to keep in mind
for the language you're working with. The from shell to driver module should make it clearer how you can
write code and how you can create
let's say that 64 bit int in your driver code.
So you will learn that later in the course
no worries,
I just want to highlight that the default which gets written into mongodb
does not depend on mongodb
but on the client you're using, in the shell it's based on Javascript,
so the default is the 64 bit double.