I have the following data structure saved in a mongodb collectionn named images
[
    {
        folder: 'cats',
        files: [
            {filename: 'redCat.jpg', _id: 1},
            {filename: 'blueCat.jpg', _id: 2},
            {filename: 'yellowCat.jpg', _id: 3},
        ]
    },{
        folder: 'dogs',
        files: [
            {filename: 'redDog.jpg', _id: 4},
            {filename: 'blueDog.jpg', _id: 5},
            {filename: 'yellowDog.jpg', _id: 6},
        ]
    },{
       ...
    }
]
I need to extract the id of a particular image, given the folder and the filename.
I'm able to get all the images in a particular folder
db.images.find({folder:"cats"}, {files:1})
but I don't know how to filter out the files array in the same query, in order to get the blueCat.jpg image id. If possible I'd avoid two sequential queries.
I tried the following query
db.images.find({folder:"cats", "files.filename":"blueCat.jpg"})
but what I get is, again, the whole file list in the cats folder. What I'm triyng to get is something like:
{filename: 'blueCat.jpg', _id: 2}
Any hint? Thanks in advance
 
    