我有两个模式,这是父集合模式:
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中通过代码来做到这一点。
请帮帮忙。
发布于 2021-08-27 03:59:59
那db.timeSheetData.updateMany({"parent_id": ObjectId(_id)})呢?
(编辑)
通过它从 collection.
TimeSheetSchema获取datahttps://stackoverflow.com/questions/68947826
复制相似问题