Querying Arrays and Sub-Documents

Hello everyone! I’ve been reviewing the lesson on array operators and sub-documents and I thought of something I can’t seem to find a solution for:

Would there be a way to query for a specific surname but it doesn’t matter where in the relationships array it is? The example we were given was based on finding “Zuckerberg” on position 0 of the array, but what if I wanted to search for “Zuckerberg” in all array positions?

That would be a job for the trusty $elemMatch operator. :slight_smile:

3 Likes

Ah, I see, the answer was right in front of me! Thank you :smile: