mongodb 添加子实体-子文档数据-nodejs
2018-06-29 本文已影响0人
章文顺
//1对多
const childSchema = new Schema({
msg: []
});
const parentSchema = new Schema({
id: 'string',
children: [childSchema]
})
const c = await model.Parent.findOneAndUpdate({
id: 'id1'
}, {
$push: { //更新子数据
children: datas
}
}, {
upsert: true, // 查不到,则添加新数据
})