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

标签 node.js mongodb mongoose

我最近将 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/

相关文章:

javascript - $从文档中的数组中提取

MongoDB:结合文本搜索和地理空间查询

javascript - 如何显示我的 MongoDB 属性?

javascript - Cypress:带有多个参数的 cy.task()

java - 使用websocket制作android聊天模块

javascript - meteor upsert 返回错误

node.js - 具有不同库存的用户的 MongoDB 数据结构

javascript - Mongodb 通过 id 在数组中找到一个对象

javascript - 如何读取 Node 中发出的简单http请求的响应

node.js - gitlab-ci 构建 grpc 失败