I have tried the same without using a separate variable search_num and use the search variable itself but the same issue persists, thats the reason I typecasted. Was tested with postman
this is my schema -
const lender_details = mongoose.Schema({
lender_id : Number,
investment_id: Number,
name: String,
email: String,
mobile_no : Number,
reg_date: Number,
live_status: String,
lender_details: String,
})
All I'm trying to do is have a common search box, that searches through investment ID,phone and email.
router.post('/', async (req,res,next) => {
search = req.body.search;
search_num = Number(search);
console.log({$regex : search_num});
await a.find({
"investment_id" :($regex : search_num),
"email" : { $regex : search } }
,{ _id : false })
The /m/ concept does not work when using a variable and so I have used regex, but after trying almost everything this error persists when I'm trying to search the investment ID which is a number -
Cast to Number failed for value "/1/" at path "investment_id" for model "lender_details"
Any and all help appreciated !
question from:
https://stackoverflow.com/questions/66061977/how-do-i-use-a-variable-with-the-mongo-like-operation-when-comparing-a-number 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…