Javascript 更新酒店客房预订阵列-mongoose

Javascript 更新酒店客房预订阵列-mongoose,javascript,node.js,mongodb,mongoose,mongodb-query,Javascript,Node.js,Mongodb,Mongoose,Mongodb Query,我在做一个酒店房间预订系统。以下是房间模型中的属性 rId: String, allocation: [{ date: Number, // 210403 == 2021-04-03 slots: [{ type: mongoose.Schema.Types.Mixed, ref: 'reservation', maxItems: 48

我在做一个酒店房间预订系统。以下是房间模型中的属性

rId: String,
        allocation: [{
            date: Number, // 210403 == 2021-04-03
            slots: [{
                type: mongoose.Schema.Types.Mixed,
                ref: 'reservation',
                maxItems: 48
            }]
        }],
        _active: Boolean
此“插槽”是一个包含48个项目(30分钟时隙)的数组。在这里,我想用用户输入更新此数组。例如,如果用户想保留2.30到3.30之间的时间,我想将数组中的两个插槽更新为“保留”。 以下代码是用于预订的控制器

reservation
        .save(reservation) //Save reservation data
        .then((data) => { // Update room slots
            var dt = req.body.checkInDate.substr(0, 10); // extract date from user input
            var tm = req.body.checkInDate.substr(11, 5); // extract time
            dt = dt.replace(/-/g, '');  // 210403 == 2021-04-03
            tm = tm.replace(/:/g, '.');
            console.log(tm)
            console.log(dt)
            Room.findOneAndUpdate({ rId: rId }, { //Update time slot
                $push: {
                    allocation: [{
                        date: dt,
                        slots: [{ tm }]
                    }]
                }
            })
上面的代码不起作用。有人能帮我吗?

演示-


不行,怎么办?你有错误吗?您没有看到的预期行为是什么?请添加具有预期输出的示例数据,如果可能,请在下面@ChristianFritz@ChristianFritz,我已经提供了我现在获得的输出。它不会根据新的输出进行更新reservations@TusharGupta-我已经提供了我现在得到的输出。它不会根据新的预订进行更新
db.collection.update(
  { rId: 1, "allocation.date": 20190701 },
  { $push: { "allocation.$[a].slots": { a: 1, b: 2 } } },
  { arrayFilters: [ { "a.date": 20190701 } ]}
)