【发布时间】:2019-10-15 18:18:15
【问题描述】:
我已经编写了以下 mongoose 函数来在 mongodb 中创建新文档
createdata: (body) => {
let sEntry = new SData(Object.assign({}, {
dataId: body.DataId
//,
//notes.message: body.message
}));
return sEntry.save();
}
这里sData 架构包含notes 数组架构。
我无法使用notes.message: body.message 为notes [] 内的message 添加价值
我的架构定义如下:
var nSchema = new Schema({
_id: {type:ObjectId, auto: true },
message: String
});
var sSchema = new Schema({
_id: {type:ObjectId, auto: true },
dataId: { type:String, unique: true },
notes: [nSchema]
}
我还想提一下,对于每个 dataId,可以有多个 notes [] 条目。但是,SData 对于每个 dataId 只能有唯一的行条目。
我希望 notes 成为 SData 集合中的一个数组。如何在不创建单独的notes 集合的情况下实现它?我应该如何修改createdata 以适应所有给定的要求。
【问题讨论】:
标签: angularjs mongoose angularjs-directive mongoose-schema mongoose-populate