Skip to content

Instantly share code, notes, and snippets.

@paulobunga
Created December 18, 2019 00:14
Show Gist options
  • Save paulobunga/8f3f811650c1fbd05433b1064d3980a5 to your computer and use it in GitHub Desktop.
Save paulobunga/8f3f811650c1fbd05433b1064d3980a5 to your computer and use it in GitHub Desktop.
Code to query products from mongoose
module.exports.viewProducts = async ( req, res, next ) => {
Product.find( {} ).exec( ( error, result ) => {
if (error) {
res.json({ status: 'ERROR', message: 'Error getting products' });
}
if (result.length > 0) {
res.json({ status: 'SUCCESS', message: 'Products found', products: result });
} else {
res.json({ status: 'NO_PRODUCTS', message: 'No products found' });
}
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment