javascript - Mongoose find all referenced documents -


does mongoose provide way find referenced documents previous query' result?

for example:

product .find(query) .exec(function(err, results) {   ...   product   .find({     '$or': [       // products _id in results.associatedproducts[]     ]   })   ... }); 

i wasn't able find way natively mongoose, see below working solution.

product   .find(query)   .exec(function(err, products) {     ...     var associatedsoftware = products.reduce(function(memo, current) {       if(current.features && current.features.associatedsoftware) {         return memo.concat(current.features.associatedsoftware.map(function(item) {           return item._id;         }));       }       return memo;     }, []);      product.find({       '$or': [         ...         { '_id': { '$in': associatedsoftware } }         ...       ]     })     .exec(function(err, associated) {       ...     });   }); 

Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -