hey i'm trying to fetch the multiple data from mongodb in mongoose with different id's but i get unkown error i try few different different approach but nothing works for me
fetcing the data
let ids = [];
for (let i = 0; i < itemforbuy.length; i++) {
ids.push(itemforbuy[i]._id);
}
let fetchingRemove = await fetch(
`${process.env.HOSTING_NAME}/api/removeProductQty`,
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
orderId: ids,
}),
}
);
let response = await fetchingRemove.json();
console.log(response);
api
import connectDb from "../../middleware/mongoose";
import Product from "../../modals/Product";
const handler = async (req, res) => {
console.log("body", req.body.orderId);
let orderId = req.body.orderId;
console.log(orderId);
let products = await Product.find().where("_id").in(orderId).exec();
console.log(products);
res.status(200).json(products);
};
export default connectDb(handler);
i tried fetching the data with array map forEach but nothing works
the error its give empty array but when i hard code the ids like
let ids = ["abc","abc","abc"]
then it finds the fetch the data. i hope you guys will help me to fix this error