Some theory first. When working with mongodb, we can basically talk about methods, filters and operators,
not just for getting data but in general but especially for getting data filters and so on
play an important role.
So in the shell, we access the database with the db command, in a mongodb driver,
this will differ slightly and you'll see it in the from shell to driver module towards the end of the
course
but there too, we will get access to the database and then to a collection in the database,
the same can be done in the shell.
Now then we can execute a method like find, insert also was a method, delete was a method,
so everything which comes after a dot here and then has parentheses like this one is called a method,
a method we execute on the collection in this case.
Now we pass some data to this method,
the parameters of the method, so to say. In find, the first argument or a parameter we can pass is a document
describing what we'll look for,
it has the format of a field name
and then the value for that field name.
Now you will learn that the value is quite flexible when finding data but in the end, this is the structure,
fields and values
and this is also what documents are all about, fields or keys however you want to name it and values
for these names or fields.
Now here, this argument for find happens to be a filter because find accepts a filter, it needs or it
can use a filter to narrow down the set of documents
it returns you.
Here we got equality or a single value filter because we want to find all documents that have an age
field where the age is exactly 32,
so we're looking for equality here,
this is a very simple filter but also one you'll use quite a lot.
Now you can also use more complex filters where you for example see something like this as a value, where
you have another document as a value which in turn has a value and where the field is then an operator
and you can see or you can recognize operators by the dollar sign at the beginning.
These are all reserved fields if you want to call them like this which are understood by mongodb
.
and this operation here as an example is called a range filter because it does not just filter for equality,
instead this will look for all documents that have an age that is greater than, that's what the gt operator
does, that is greater than the value, so greater than 30.
This is how this works and what we will work with in this module, we'll learn a bunch of different operators
and different ways of using them and different ways of filtering therefore.
But in the end, this is always the structure you will recognize.