I’m getting this error in my API using NodeJS, Express, and MongoDB when doing a batch query (GET). I am able to POST, PUT, and DELETE multiple documents by _id but for some reason I get this error when doing this query:
Here is my API:
//Use batch object to retrieve multiple objects in one operation
app.get('/users/batchquery', passport.authenticate('jwt', { session: false }), async (req, res) => {
const { userIds } = req.query;
try {
// Split the userIds into an array
const ids = userIds.split(',');
// Perform the query using the $in operator to fetch multiple users at once
const users = await Users.find({ _id: { $in: ids } });
// Send the response with the retrieved users
res.json(users);
} catch (error) {
// Handle errors
res.status(500).json({ error: 'An error occurred' });
}
});
Have been at this for hours and so far have not found any fix online. Would appreciate any advice Thanks!