Here is my code
module.exports.comparator = function(req, res){
Buyer
.find()
.exec(function (err, buyer) {
if (err) {
console.log("Error finding buyer");
res
.status(500)
.json(err);
} else {
console.log("Found buyer", buyer.length);
res
.json(buyer);
buyerData = buyer;
}
});
Seller
.find()
.exec(function (err, seller) {
if (err) {
console.log("Error finding seller");
res
.status(500)
.json(err);
} else {
console.log("Found seller", seller.length);
res
.json(seller);
sellerData = seller;
}
});
})
As you can see i am trying to get 2 collections and storing them into a variable because i want to do further coding as...
buyerData.forEach((buyer) => {
sellerData.forEach((seller) => {
console.log(buyer.bidPrice , seller.askPrice)
if(buyer.bidPrice == seller.askPrice){
but whenever i run it i get an error like this
Error: Can't set headers after they are sent.
at validateHeader (_http_outgoing.js:491:11)
at ServerResponse.setHeader (_http_outgoing.js:498:3)
at ServerResponse.header (E:\eClass\node_modules\express\lib\response.js:767:10)
at ServerResponse.send (E:\eClass\node_modules\express\lib\response.js:170:12)
So is it possible for me to get the data from these different collections and do other computations on them?