Override casting logic for individual schema path
Re: #7045, #8300
const schema = new Schema({
myId: {
type: ObjectId,
cast: false // Disable casting just for this path
},
myNum: {
type: Number,
cast: v => { const ret = +v; assert.equal(typeof ret, 'number'); return ret; } // Override casting just for this path
}
});
hello, @vkarpov15 ,not used this setting, const schema = new Schema({ myId: { type: String, cast: false // Disable casting just for this path } }); how to disable 'myId' not cast .eg: new schema(myId: 123)
@hughdev this feature is not implemented yet, that’s why this issue is still open :)
Can you please elaborate what you’re trying to accomplish with this functionality?
Hi, good day, also having this issue. I saw previous issues and saw that they solved the case for mongoose.Number.cast(false) but not for mongoose.String.cast(false).
I believe it is also important to extend this functionality also to String. My example is simple, I have a unit test which tests if field is number instead of string, this should throw an error, but instead it passes because before it is saved, the number is casted to a string.
@SirMauri this functionality hasn't been implemented yet. We will implement it for the next minor release.