我有以下架构:
var Person = new Schema({
persondetails: {
name: {
type: String,
uppercase: true,
required: true
},
nationalities: [ {
nationality : String
}]
});
和预检函数来检查修改后的路径:
schema
.pre('save', function(next) {
var document = this;
_.each(document.modifiedPaths(), function(path) {
console.log(path);
});
return next();
});
如果我这样做:
new Person({persondetails: {
name: 'Some Name',
nationalities: [ {nationality: 'Some Country'}]
}
)
甚至选择已经存在的“人物”并在其国籍阵列中添加新元素,
预先挂钩的打印:
persondetails
persondetails.name
persondetails.nationalities
但我也期待着'persondetails.nationalities.0.nationality'。
这是预期的行为还是我错过了什么?