MongoDB return documents where the id is within an array of ids


#1

Greetings,

How would I query a collection and return only the documents where the id is within an array.

Ex.
I have an admin panel where I have a multi select box which contains ids from a specific collection.
On the homepage based on the selected posts I want the ids that are within that array to be the only documents returned to the homepage.

I’ve seen examples for $in however this only seems to return one document.


#2

Hi, may be :
//publication:
Meteor.publish(‘getFilterItems’,function(ids){
return Items.find({_id : {$in : ids}});
})
//home page (client script):
var ids = …
//subcribe getFilterItems with param : ids
//find again
var items = Items.find({_id : {$in : ids}});


#3

Thank you for the solution. I will give this a shot.