I need to find a user by his mongodb collection's _id ,
in need the search to be done using the first 5 characters in the user id
example with 5e9cca i can find the collection id 5e9cca24beabb96a4caedc35
var id = req.body.id
User.findById({ _id : { $regex: '^id', $options: 'i' } },
(err, user) => {
if (err) {
console.log(err);
res.status(400)
}
with this code i got this error :
MongooseError [CastError]: Cast to ObjectId failed for value "{ _id: { '$regex': '^id', '$options': 'i' } }" at path "_id" for model "User"
PS : The search using the hole id is working