So time to practice what we did.
For this, I'll first of all,
fetch all my restaurants again
and now I wanna leave a review for the Berlin Burgerhouse.
For this, I'll again repeat this insert one command.
I pressed the up key to get to this command again here.
And now this time, it's not for the Munich Schnitzelhouse.
Instead, it will be for this Berlin Burgerhouse.
So I'll copy that name, copy that string here, this ID,
and replace this ID and object ID with it.
And I'll leave the date for convenience reasons,
change the review text a little bit though.
This was amazing.
And change the rating here to five,
and I will leave my name.
And actually here, I was lacking a closing parenthesis
so now I insert this and now this review was also inserted.
So now we got two reviews,
if we find that we got two
restaurants and of course we could add more,
but now I want to instead practice querying.
And let's say we want to find all the reviews
that have a rating greater than four.
In this case, that would only be one review.
To do this,
we can execute db reviews find,
and then pass our condition here.
And you'll learn that here, for example,
we can look for reviews that have a rating of five
like this,
but we can also do things like searching for values
greater than four or a smaller than three
or whatever you want to do.
For this, instead of passing a value here,
you pass an object and then you use the special dollar sign
gt or lt commands here.
There also is lte and gte,
which stands for a greater than or equal
or just greater than, or lower than or lower than and equal.
So these again are reserved names,
reserved filter conditions that you can use when filtering.
It's important that you pass them inside of an object,
which you pass as a value for the key where you want
to filter.
And then for example,
you can search for reviews where the rating is greater
than four by running this command.
And of course,
we only find one review here because the other review
had a rating of three, which is not bigger than four.
Now you can find a list of all these supported operators
in the official Mongo DB documentation.
If you search for query and projection operators,
or you click into reference operators,
query and projection operators,
here you find comparison operators like gt,
which I just showed you.
And there are more operators,
also for concatenating conditions and so on.
Again, I got a full Mongo DB course where you can learn
all about that in great depth,
but the official docs here of course are also a great place
to play around with that and practice these things.
For example,
if you would want to find all reviews that are greater
than four and smaller than three,
you could write this differently and write dollar sign and,
and then a list of all the conditions that should be met.
That's what you'll learn in the official documentation here.
And then in there in this list, you have objects.
So opening and closing curly braces,
where you look for a rating gt one
and then separated by a comma another object
where you look for rating lt three.
So I guess we're looking for ratings
with a value of two here,
but I just want to show you how you could,
for example, also combine conditions.
And here, of course,
I don't find anything because we have no review
with a rating of two in this case.
Now this might look strange at first.
I just want to show you how this looks like.
And it is actually a syntax that will quickly
become familiar the more you work with it.
Again, the official docs or dedicated courses
are great places to dive deeper into that.
But of course,
we're also going to work with Mongo DB
and also run different kinds of queries,
again throughout this course, for example,
in the next course section.
So that's how we can query data and how we can insert data.
Now let's also quickly, again,
practice updating and deleting data.
And for this,
I'll come back to my restaurants and find all my restaurants
here.
And let's see here.
I actually do want to update the address
of my Munich Schnitzelhouse again.
Now of course,
also feel free to practice this on your own.
We did already make such update a couple of lectures
ago already.
Now I will grab this ID here.
Actually,
we can grab this entire code snippet here to identify
this restaurant by this ID and then to update it,
we can run update one because I only want to update
the first matching document and look for the document
where the ID is equal to this object ID.
And then we pass a second argument,
a second parameter value to update one.
And here you now use the special dollar sign set key,
which is understood by Mongo DB.
And another pair of curly braces.
So you work a lot of curly braces when working with
Mongo DB, as you can see.
And then here we point at our nested field
by using address dot street between quotes, like this.
And then the value you want to set here,
let's say schnitzel street.
And this is how we could update the street field
in the nested address document in the restaurant
with this ID.
Hit enter.
You'll see one document was modified.
And if we now, again, simply find all restaurants,
here we have the new street.
Now last, but not least,
we can of course also delete documents.
And for example, delete a review.
For this, I'll quickly find all of them again.
And let's say, I want to delete to this first review.
Well, then we can just grab that ID to identify it
by that ID.
And then run db reviews delete one.
And between curly braces search for the ID,
which has this object ID and hit enter.
And now this was deleted. And of course, therefore,
if we try to find all the reviews,
this review is now missing.
So these are the CRUD operations we can run with Mongo DB.
That's the general base syntax you should understand.
Again, we'll see more examples throughout this course.
And most importantly,
you now should understand what the idea is behind
storing data in a NoSQL database.
That we don't work with dozens of tables,
but that we instead try to plan for the queries
we're about to run and that we then store relate data
together.
Not all the time.
As you saw with restaurants and reviews,
where we still had two collections, but often as you,
for example,
saw with restaurants and the addresses
of these restaurants.