gpt4 book ai didi

node.js - mongoose document.validate 从 4.4x 更新到 ^4.5.1 后抛出 RangeError

转载 作者:太空宇宙 更新时间:2023-11-04 00:24:59 24 4
gpt4 key购买 nike

我最近将 mongoose 更新到了 4.5.1 或更高版本。 Document.validate 现在抛出“RangeError:超出最大调用堆栈大小” 当我的架构具有嵌入式文档数组时,会发生这种情况。但如果数组为空,则验证成功。对于我的所有模式都是如此。

这是我的代码示例

var userSchema = new Schema({
name: { type: String, required: true },
roles: { type: [userRoleSchema]: default [] }
})

var userRoleSchema = new Schema({
type: { type: String, required: true },
organization: { type: Schema.Types.ObjectId, ref: 'organization', required: false },
})

// Later when I call this
userDocument.validate((err) => { /* I don't even end up here */ })

我已经在 4.4.1、4.4.2 和 4.5.0 上测试了我的代码,没有任何问题。但我确实需要使用 4.5.1 或更高版本,这就是我遇到此问题的时候。我已经找了好几个小时了,但没有发现有人遇到这个问题。任何帮助将不胜感激!

最佳答案

我解决了这个问题,将所有嵌入式数组方案的架构类型更改为 Schema.Types.Mixed。缺点是我不再对这些模式进行验证,但它至少解决了问题。

关于node.js - mongoose document.validate 从 4.4x 更新到 ^4.5.1 后抛出 RangeError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43112885/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com