【发布时间】:2021-08-27 03:49:47
【问题描述】:
我有 2 个架构,这是父集合架构:
const TimesheetSchema = Schema({
managersComment: {
type: String,
},
weekNum: {
type: Number,
},
year: {
type: Number,
},
user: { type: Schema.Types.ObjectId, ref: userModel },
status: {
type: String,
enum: ["Saved", "Submitted", "Approved", "Rejected"],
},
data: [{ type: Schema.Types.ObjectId, ref: TimesheetIndividualData }]
});
这是子集合架构
const TimesheetDataSchema = new Schema(
{
workingDate: {
type: Date,
},
dayVal: {
type: Number,
},
user: { type: Schema.Types.ObjectId, ref: userModel },
parentId: { type: String },
status: { type: String }
},
{ timestamps: true }
);
我想根据parentId更新TimesheetDataSchema(child collection)中的所有status字段,这里parentId基本上就是TimesheetSchema (parent collection)的_id。
不知道如何通过 mongoose/mongo 中的查询来做到这一点,所以我试图通过 express 中的代码来做到这一点。
请帮忙。
【问题讨论】:
标签: node.js mongodb express mongoose