这是我的模式
const winSchema = new mongoose.Schema( {
windo_no:Number,
time:{
start_time: {hours: {
type: Number, min: 0, max: 23
},
minutes: {
type: Number, min: 0, max: 59
}
},
current_time: {hours: {
type: Number, min: 0, max: 23
},
minutes: {
type: Number, min: 0, max: 59
}},
end_time: {hours: {
type: Number, min: 0, max: 23
},
minutes: {
type: Number, min: 0, max: 59
}},
},
date:[{
date:String ,
holiday:Boolean,
allocation:[{
tokenid:Number,
compelte:{
type: Boolean,
default: false
},
m_number:Number,
services_id:Number,
allocated_time:{hours: {
type: Number, min: 0, max: 23
},
minutes: {
type: Number, min: 0, max: 59
}},
}]
}]
});
module.exports = mongoose.model('Window', winSchema)
我将每天运行查询,其中我想为所有窗口更新current_time将等于start_time一次尝试执行updatemany((,但如何从已插入的字段值中获取和设置值
// set current_time=starttime
router.post("/settime", async (req, res) => {
let result = await model.updateMany({ },
{
$push: {time:{ current_time: {hours:11}} },
},
)});在这里,尽管我写了hours:11,但我想添加start_time hours字段值
let result2 = await model.updateMany({},{
$push:
// {'time.current_time': 'time.start_time'}
{time:{ current_time: "$start_time"} },
})
let result2 = await model.updateMany({},
[{$set:{"time.current_time":"$time.start_time"}}])