Find if string ends on some of the string in array

I have a collection with some document sctructure like this
{
name: string
emails:[string, string]
}
I have exact name and an email. And I need to find document that have that name and have the email in array that MAY BE THE END of given email. (Example: array is [1@google.com, 2@google.com], given email is 31@google.com - so its true, we have an email that may be the end of the given)
Question - can I write this in query or it only can be done in code. I don’t want to use that much RAM because the array may be pretty big.
I am new in Mongo, maybe I just dont know the basics but I didn`t find the answer.

Hello @Andrew_Kondratyev, Welcome to the MongoDB community forum,

You can directly check your input in array of strings without specifying any position,

.findOne({ emails: "search email" })

Checkout the documentation with detailed examples:

I don’t need exact match. Just some of string in array shoud be the end of the given string
Like we have:

emails: ["endOfString", "otherString"]

And this should match with

givenEmail: "startOfString_endOfString"

Or I can maybe store them somehow?

I would suggest splitting your input email by "_" and do the exact match with the last value.