Meteor find using $in with array of Ids Meteor find using $in with array of Ids mongodb mongodb

Meteor find using $in with array of Ids


You could rewrite your code this way:

var producerIds = Blocks.find({    "location": location}).map(function (block) { return block.producerId; });var producersList = Producers.find({    "organizationId": user.organizationId,    "_id": { "$in": producerIds }}).map(function (obj) {    return {        "text": obj.name,        "id": obj._id    };});


Here's a cleaner answer based on Chidrams. Working code example.

var colleagueIds = Posts.find({ type:"colleagues" }).map(function (person) { return person.title; });        //console.log(colleagueIds);        return Meteor.users.find({            "_id": { "$in": colleagueIds }        });

Note that the map function returns the title cursor of my post object. It'll make sense if your a good Wordpress developer. But, you probably want to return the _id of the object.