是否可以禁用Mongoose SchemaTypes的自动类型转换? [英] Is it possible to disable automatic type casting for Mongoose SchemaTypes?
本文介绍了是否可以禁用Mongoose SchemaTypes的自动类型转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于具有此架构的模型...
For a model with this Schema...
{
name: { type: String }
}
{
name: { type: String }
}
...以下自动将提供的值强制转换为字符串,而不是强制类型:
...the following automatically casts the provided value to a string instead of enforcing the type:
document.name = 2;
document.validate(err => {
// Err is null, document.name === '2'
})
document.name = 2;
document.validate(err => {
// Err is null, document.name === '2'
})
是否有一种简单的方法可以禁用此行为?
Is there a simple way to disable this behaviour?
推荐答案
Just in case anyone else stumbles upon this, it looks like mongoose will be supporting this according to this issue.
这篇关于是否可以禁用Mongoose SchemaTypes的自动类型转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文