So after this useful piece of advice, let's now have a look at some dedicated array query selectors that
can help us find the right query,
let's start with size,
size is pretty straightforward
Now here in our collection, if we have a look at all our users, we can see that they all have the same
amount of hobbies, they all have two hobbies.
Now let's therefore add a new user with insertOne and that user will generally follow the scheme and
have a name,
whoops, we don't need to wrap that but we could,
the name is Chris let's say
and we can specify an age and the other parts that doesn't really matter,
let's specify the hobbies that matters.
And we can even use a different approach here and say sports, cooking and hiking, like this,
so here I don't have embedded documents, I could add them,
it really doesn't matter,
to save time and space I'll just use strings.
So now I have one new user in the database,
Chris and now I want to find all users who have three hobbies which should be just Chris because the
other users have two
and it doesn't matter whether a hobby is an embedded document or just a string,
it's just the amount of items in the hobbies array that matters. To find all users with exactly three
hobbies, I can look into my users with find and now the value for find is that I use hobbies and I'm looking
for a size of three, written like this.
If I hit enter,
I only find Chris.
Now what's important to understand about this command by the way is that this has to be an exact number,
you can't say give me anything with more than two items. If you need something like this,
you'll have to retrieve your data differently,
this is something mongodb does not support yet, you can only look for exact matches here.