我正在尝试使用Mongoose进行客户端模型验证。我有以下代码(这是一个React组件):
import templateSchema from '../../../shared/schemas/templateSchema.js';
var mongoose = require('mongoose');
var TemplateDocSchema = new mongoose.Schema(templateSchema);
class TemplateEditInfo extends Component {
...
saveStage(e) {
var doc = new mongoose.Document({}, TemplateDocSchema);
doc.validate(function(error) {
});
}
...
}
doc.validate
功能在浏览器中引发了以下错误(最新的Chrome):
未捕获RangeError:超出最大调用堆栈大小 Object.exports.deprecate(eval at(app.js:866),:65:29)at Promise.eval(eval at(app.js:866),:69:22)在Promise.eval(eval at (app.js:866),:69:41)在Promise.eval(eval at(app.js:866),:69:41) 在Promise.eval(eval at(app.js:866),:69:41)在Promise.eval(eval) at(app.js:866),:69:41)在Promise.eval(eval at(app.js:866), :69:41)在Promise.eval(eval at(app.js:866),:69:41)在Promise.eval (eval at(app.js:866),:69:41)在Promise.eval(eval at(app.js:866), :69:41)
架构如下:
const templateSchema = {
ref: {type: Number}
};
export default templateSchema;
答案 0 :(得分:0)
我需要安装一个Promise包来解决这个问题:
var mongoose = require('mongoose');
var bluebird = require('bluebird');
mongoose.Promise = bluebird;