How to filter collection on nested field values


I have a meteor collection with the below structure. This actually comes from a Meteor-files collection by ostrio.

 "_id" : "HsXoZ6bxkx5kMcJtm", 
"name" : "trees.jpg", 
"meta" : { "artist_id" : "QkmYdsZsMmRzqTg58" , "artist": "some name"}, 
"mime-type" : "audio/mp3", 
"userId" : "QkmYdsZsMmRzqTg58", 
"_collectionName" : "images" 

I define a publication

Meteor.publish('files.artist', function publishUserImages(){
   return Images.find({meta: {artist_id: this.userId}).cursor;

I want to filter on the meta key, to return all items with artist_id.
My current filter will get only those Images where meta has the exact value {artist_id: "QkmYdsZsMmRzqTg58"}. The filter won’t return the item shown above since it the meta value has an extra key artist

How do I construct an appropriate filter?


If think you need $elemMatch:
But I am not too much of a MongoWizzard :slight_smile:


Thanks man for the suggestion. But I got what I was looking for on SO.

    Meteor.publish('files.artist', function publishAudios(){
        return Audios.find({'meta.artist_id': this.userId}).cursor;