Filtering all items of specific type (ref document) Filtering all items of specific type (ref document) mongoose mongoose

Filtering all items of specific type (ref document)


The solution was to create a method in my service like so:

service.autoCompleteType = function(query) {  var productList = null;  var products = [];  return Product    .find()    .populate('type')    .exec()    .then(function(products){      productList = products;    })    .then(function(quantities){      for (var i in productList) {        if (productList[i].type.code === query) {          products.push(productList[i]);        }      }    return products;  });};

This allowed me to query type.code as required and returned everything matching query