【发布时间】:2020-09-03 18:17:49
【问题描述】:
这是课程架构,我想推送 内容对象,但我找不到什么好方法。请帮忙。
import mongoose from "mongoose";
export const Schema = new mongoose.Schema({
course_en: { type: String },
course: { type: String },
module: [
{
_id: {
type: String
},
module_en: String,
module: String,
content: [
{
_id: { type: String }
content_en: String,
content: String,
}
],
}
],
});
const Course = mongoose.model("Course", Schema);
export default Course;
这是我尝试过的代码,但不起作用,它只能添加 模块对象
db.update(
{ _id: _id, "module._id": module_id },
{
$push: { content: data }
}
)
.then((result: any) => {
console.log(`Content Posted ${result}`);
response.send({ "status": "success" });
})
.catch((error: any) => {
console.log(`Error ${error}`);
response.send({ "status": "fail" });
});
【问题讨论】:
标签: node.js database mongodb express mongoose