【发布时间】:2021-07-19 18:01:22
【问题描述】:
我是 mongoDB 和后端的新手。我有一个嵌套的 MongoDB 模型模式。我需要更新、删除和添加该嵌套对象/数组。我该怎么做?
如何从列数组和恢复数组中删除/添加/更新项目。
const userSchema = new Schema({
name: {
type: String,
required: true,
},
email: {
type: String,
required: true,
},
password: {
type: String,
},
columns: [
{
title: {
type: String,
required: true,
},
resumes: [
{
name: {
type: String,
required: true,
},
resume: {
type: String,
required: true,
},
},
],
},
],
});
const Users = mongoose.model('Users', userSchema);
这是我的架构
【问题讨论】:
-
只需访问变量,如果它们在一个数组中,然后循环访问它并使用条件访问您想要的变量。