node.js - Mongoose 更新将虚拟填充保存到文档
问题描述
由于某种原因,猫鼬没有正确更新。它正在添加到我Document
的虚拟中。
const BlogSchema: Schema = new Schema<Blog>({
clientId: {
type: Schema.Types.ObjectId
}
//...
})
ClientSchema.virtual('client', {
ref: 'clients',
localField: 'clientId',
foreignField: '_id',
justOne: true,
});
//...
return this.clientScreeningsModel
.findById(id)
.populate('client', 'email username')
.lean(true);
这工作正常。
但是在客户端,我说我想更新或创建一个新的Document
,然后我发送整个Object
例如:
{
_id: 'something',
clientId: 'previousId',
client: {
email: 'foo@bar.com',
username: 'JohnDoe'
}
}
它也会将客户端对象保存到我的Document
,猫鼬不知道它是虚拟的吗?
在此先感谢您的帮助:)
解决方案
推荐阅读
- aspnetboilerplate - 从 Angular 上传文件 - 将文件内容设置为 Dto
- python - 将新工作表添加到 2000 xlsx 文件 - Openpyxl 非常慢
- elixir - 是否可以在 ecto 查询中对预加载进行选择?
- python - 检查excel表中是否存在pandas DataFrame系列中的值
- magento-2.3 - 所有类别设置为noindex,follow
- c# - 可空引用类型和 ToString() 重载
- amazon-s3 - How to grant public read only access to S3 Bucket in AWS SAM template
- android - Flutter 需要 Android SDK 28 和 Android BuildTools 28.0.3
- c# - 使用 C# 客户端连接到 socket.io,但使用/加入房间
- amazon-web-services - 如何使用 AWS EC2 实例 (Ubuntu AMI) 安装第三方 SSL 证书?它会花费一次性还是每月?