Reputation: 31
this is my route handler
router.get("/get-bookmarks", async (req, res) => {
const bookmarks = await Post.find({ _id: { $all: req.body.idList } });
if (!bookmarks) return res.status(404).send("No bookmarks yet");
return res.send(bookmarks);
});
this is the data to search using postman
{
"idList": ["60c07302f033f51f6c87c986","60c07399f033f51f6c87c989","60c0736ff033f51f6c87c988"]
}
Upvotes: 1
Views: 543
Reputation: 20304
You can do it with $in
operator, like this:
Post.find({ _id: { $in: req.body.idList } });
Here is the working example: https://mongoplayground.net/p/gs-nuaB-_Ux
Upvotes: 1