Let's now come to evaluation
operators. Now json schema is something I covered in the document schema module,
you could also use it in a query to find elements that have a certain document schema,
so you set up a schema there as a value just as shown for validation. Mod is the modulus operator,
so here you could basically divide a field value with a certain number and then check if the result
is ok for you. Text is something
I'll come back later in the indexes module where it's deprecated and basically replaced with expression,
so in the next lectures we'll have a look at expression and regex
and let's start with regex.
Regex allows you to search for text and for that, I'll switch back to my movie data database
and run some query on my movies,
remember if we quickly find one, there we also have a summary field.
Now let's say we want to search for a text snippet in there, we want to search for a musical just because
I see it here.
Now what we could of course think that it will work is that
we access our movies and then we find all movies where summary, that was the field name is equal to musical.
But if I do it like this, I find no entries because this looks for full equality,
so it would find all documents where summary is exactly equal to musical, written like this. Well musical
is just one word in there though and not the complete entry,
so this does not work.
Now for finding text snippets, the most efficient way of doing it is to use a text index, something you
will learn about in the indexing module
but if you don't have such an index, you can't use one or you only have very short text snippets which summary
is already a bit above to be honest
but let's still use it, then you can use regex query but be aware that it will not be super performant.
So what you could do here is you can specify $regex and regex stands for regular expression
which is a way of searching text for certain patterns. Now you can dive deeper into regex, setting
up these patterns can be quite complex,
we'll keep it simple here,
a pattern is always surrounded by forward slashes and in-between you define your pattern. The simplest pattern
possible
is that you just type a word
and now this will not look for full equality but it will look for this word in all the summaries and
return all documents where in the summary, this word can be found.
So if I now hit enter,
now we find this item here where we see musical here
and note that it's a different item than we saw before because if I scroll up,
then here we have that musical comedy we saw earlier.
So this is regex, nice for searching text but not the most efficient way of doing that,
hence definitely have a look at the text index in the indexes module.
Now that was regex,
now what does expression do?