I have a Schema Classroom with properties:
_id
studentEmails (array of Strings. Each student has an unique email)
I am given an array of Classroom ids, and I want to find every student email that belongs one of those classrooms, without duplicates. How do I do this? I was thinking I could get every student email and then remove duplicates later, but I would much rather do it through mongoose.
For example, if I had the following classrooms:
_id: 1
studentEmails: ["[email protected]", "[email protected]"]
_id: 2
studentEmails: ["[email protected]", "[email protected]"]
And the following query parameter:
[1, 2]
I want to get [[email protected], [email protected], [email protected]]. The _id is a mongoose ObjectId, but simplified in the example.