I have a schema in Mongoose:
const member = new Schema({
_id: { type: String, required: true },
...
});
but when I use await MemberModel.findOne({ _id: req.params.userID });
in an express request handler, I get a CastError: Cast to ObjectId failed for value "MY_SECRET_VALUE" at path "_id" for model "Member".
As you can see, I have set _id
's type to String
in the Schema - why is it not allowing me to search for the _id by a String value?