我正在开发一个接受基本邀请的端点,我需要通过参数(起诉Express)中提供的ID获得通知,然后更新他的result
字段.接口/架构如下所示:
const NotiticationSchema = new Schema<Notitication>({
title: { type: String, required: true },
description: { type: String, default: null },
date: { type: Date, default: Date.now() },
type: { type: String, required: true },
navigation: {
type: String,
enum: NotificationNav,
required: true
},
navigationId: {
type: String,
enum: NotificationIds,
required: true
},
teamId: { type: String, required: true },
result: {
type: {
accepted: { type: Boolean, required: true },
motivation: { type: String, required: true }
},
default: null
}
});
这是我目前使用的代码:
const notification = await NotiticationModel.findByIdAndUpdate(req.params["id"]!, { $set: { result: { accepted: true, motivation: null } } });
预期输出应为:
{
...
"result": {
"accepted": true,
"motivation": null
}
}
NotiticationModel.findByIdAndUpdate()
做什么:
{
...
"result": {
"accepted": true,
"motivation": null,
"_id": {
"$oid": "65b23b495a60bda2c6e67996"
}
}
}
我从来没有遇到过这种行为,有谁能帮忙吗?
另外,我已经问过人工智能了,它没有给出任何有用的建议.