mongoose document.validate在从4.4x更新到^ 4.5.1之后抛出RangeError

我最近更新了mongoose4.5.1或任何以上的真的。 Document.validate现在抛出“RangeError:超出最大调用堆栈大小”当我的模式具有embedded式文档数组时,会发生这种情况。 虽然如果数组是空的,validation是成功的。 所有我的模式都是如此。

这是我的代码的一个例子

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上testing了我的代码,在那里我没有问题。 但我真的需要使用4.5.1或更高,这是当我得到这个问题。 我已经找了几个小时,但没有发现任何人有这个问题。 任何帮助,将不胜感激!

我解决了它的架构types更改为Schema.Types.Mixed所有我的embedded式arraysscheme。 缺点是我不再validation这些模式,但至less解决了这个问题。