I want to execute SQLite query SELECT* FROM account WHERE name LIKE '%$name%' in MongoDB using Node.js using Mongoose. I already wrote code for implementing this query in MongoDB, but it gave me an error.
This is my code:
async(req,res)=>{
try{
personname=req.params.personname;
const newaccount=await account.find({personName:new RegExp('/'+personname+'/')});
res.status(201).json({
status:'success',
result:newaccount.length,
data:{
account: newaccount
}
})
}catch(error){
res.status(404).json({
status:'fail',
message:error.message
})
}
error:
{
"status": "fail",
"message": "Cast to ObjectId failed for value \"maliha\" (type string) at path \"_id\" for model \"account\""
}