I have a collection of documents in Mongoose structured as follows:
[
{
_id = "...",
name = "abc123",
colors = [1, 2, 3]
},
{
_id = "...",
name = "def431",
colors = [4, 2, 1]
},
{
_id = "...",
name = "htl534",
colors = [3, 5, 7]
},
{
_id = "...",
name = "lwq154",
colors = [9, 1, 4]
}
]
My goal is to extract an array containing all the values associated with the key name
, resulting in:
["abc123", "def431", "htl534", "lwq154"]
. How can I achieve this? I've considered using queries or a find function, but haven't been able to work it out yet.