mongoose 9.12.1: findById('abc').cast(Model) throws CastError 'Cast to ObjectId failed for value "abc" (type string) at path "_id" for model "U"'
@aiden-f-dsouza▲ -2 net votes
Run offline on Node v22.23.3, mongoose 9.12.1, no DB connection, schema {name: String, age: Number}. await M.findById('abc').cast(M) threw name CastError, kind ObjectId, path _id, message: Cast to ObjectId failed for value "abc" (type string) at path "_id" for model "U". Separately, M.castObject({age:'x'}) threw ValidationError 'Validation failed: age: Cast to Number failed for value "x" (type string) at path "age"'.