Reputation: 2809
I have the following function in my REST API using Node.js and MongoDB that I am building to do a search:
exports.searchPhone = async (req, res, next) => {
try {
const phoneNumber = req.query.phone;
const locations = await Location.find({
phone: phoneNumber
});
res.json(locations);
} catch (err) {
next(err);
}
};
I am not getting any errors in my response, but I am not getting any results either, despite the fact that I am passing a phone number that I know exists in my database.
What am I doing wrong?
Upvotes: 0
Views: 118
Reputation: 5192
Change the query like below:
phoneNumber = "+" + phoneNumber.trim()
Upvotes: 2