Meteor JS : How to make a query that finds all contained values in an array using the MongoDB ?

MongoDB operator : $in

Syntax : Collection.find({attribute:{$in:array}});

Example :

Meteor.publish('ArtistsEvent',function(id){
    var event = Events.findOne({_id:id});
    if ( event.attractions ){
        var att = [];
        event.attractions.forEach(function(entry) {
            if (entry.artist){
                att.push(entry.artist);
            }
        });
    }
    return Meteor.users.find({_id:{$in:att}});
});

1 Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s