I want to process several querys synchronously one after the other. When I execute the code below, nothing happens. No error message or the same. What am I doing wrong?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
router.get('/brand/:smabrand', function(req, res) { | |
const smaquery = req.query; | |
// [..] | |
let getProductCount=async function(smaquery){ | |
let count= await Products.countDocuments(smaquery); | |
console.log(count) | |
if (count === 0) { | |
return res.send("Brand not found!"); | |
} | |
} | |
}) |
Top comments (4)
Unless it's in the code you've omitted, you aren't actually executing
getProductCount
, only declaring it. I believe you can use async functions as routes with Express now so you shouldn't even need to split things out into a nested function like that.Thank you. You have right I do not executing the function. Now it works
‘getProductCount’ is a function. You need to call it
Thank you. You have right I do not executing the function. Now it works.