【发布时间】:2020-09-04 07:37:49
【问题描述】:
我有一个如下所示的模型架构:
title: { Type: String }
description: {Type: String}
....
....
workingwith: [
{
user: {
type: mongoose.Schema.Types.ObjectId,
ref: 'User'
}
}
],
我正在尝试构建一个更新函数,该函数删除workingwith 数组中的所有对象,除了指定的对象:
await Job.findByIdAndUpdate(
request.resourceId,
{
$set: { positionFilled: true },
$pull: { workingwith: { $elementMatch: { $not: { user: request.user } } } }
},
{
new: true,
runValidators: true
}
);
有没有办法做我正在寻找的事情?
这是我已经尝试过的:
workingwith: { $ne: { user: request.user } }
////////
workingwith: { $not: { user: request.user } }
提前致谢。
【问题讨论】:
标签: javascript arrays mongodb mongoose