我正在尝试使用JSON文件来填充我的数据库 - 我已经成功使用了其他一些文件,但是这个文件/模型正在抛出验证错误并且错误对我没有多大帮助 - 他们说那里是一个验证错误,他们甚至有点告诉我它在schematype.js文件中的forEach行 - 但我不会去更改node-modules文件夹中的文件...特别是当我认为这是我的编码时故障。
“mongoose”:“4.9.8”
这是在APP.JS中 - 调用/ loaddata:
fact 10.5
这是在我的模型页面中:
app.get('/api/loadData', (req, res) => {
var Xs = require( './_mock_data/x.json' );
for ( var i in Xs ) {
X.create( Xs[i] );
console.log( Xs[i] );
};
});
我的JSON文件看起来像这样 - 我认为有问题的数据是混合类型的“人” - 我的混淆是因为它是一个人的数组,所以forEach应该循环它 - 为什么它失败了?
const XSchema = mongoose.Schema({
name:{
type: String,
required: true
},
state:{
type: String
},
type:{
type: String
},
people:{
type: [mongoose.Schema.Types.Mixed]
},
create_date:{
type: Date,
default: Date.now
}
});
最后 - 错误 -
[
{
"name": "Building One",
"state": "Alaska",
"people": [{
"position": "Chair",
"department": "Sales",
"email": "aftcs@blah.io",
"phone": "",
"name": "John Smith"
}],
"type": "Business"
}, {
"name": "Fairbanks Folly",
"state": "Maine",
"people": [{
"position": "Sitting",
"department": "AAA",
"email": "ffjda@uafert.com",
"phone": "",
"name": "Jane Aspnes"
}, {
"position": "Standing",
"department": "BBB",
"email": "jmbicigo@Maine.com",
"phone": "",
"name": "James Bicigo"
}, {
"position": "Lying",
"department": "AAA",
"email": "kmbutlerhopkins@Craf.org",
"phone": "",
"name": "Kam Butler-Hopkins"
}],
"type": "Other"
}
]
再一次,非常感谢任何帮助和见解!