Get names from document array with name ids

I have a document with and array (I get the document _id from the URL)

"categoryArray" : [ 

I have another collection with names and _id that match the categoryArray ids

howto loop the categoryArray and show the names that match in a list?

const categoryArray = [ 

Categories.find({_id: {$in: categoryArray}}, {fields: {name: 1})

// remove fields object if needing the entire document

May need to add .fetch() to end depending on needing cursor or array.

Dont understand your solution, I’m still a mongodb beginner

Should the code you have written do this:

I have:

categories collection: _id, category, categoryArray

categoryArray = ids on category names (sub levels to categories)


  'crumarray': function(){
  var thisurl_catId = Router.current().params._id;

 HERE i need some code that take the categoryArray (2,4,6) in one categories _id and match it with categories collection _id and return name like 

return (loop) categories from array find category names and show as a breadcrum


Its for breadcrums

cat1 < cat2 < cat3

Got it to work with:

var thecat = Categories.findOne({_id: thisurl_catId2})
return Categories.find({_id: { $in: thecat.categoryArray}})

Just a design note:

Since the breadcrumb usually represents the current navigation as a hierarchy, you can structure the url params so that the breadcrumb can be represented mostly with that information. For example, depending on how deep the breadcrumb is,


would make breadcrumb

Home / Notes / List / Archived / Apples - Oranges + query param: c for categories

Then the breadcrumb logic just composes itself based on what is in the url params and query params. It can look up something in mongo if needed, but it doesn’t have to track all the variations of the breadcrumb for every record.

I wouldn’t even use the different categories in the breadcrumb, that is more filter logic for search labels, than hierarchy information.

By tracking state in the url, you get a lot of benefits you can use in your code’s logic. If you are worried about the params logic, you can start off more using mostly query params since they don’t affect the route path directly.