node.js - 使用猫鼬从不同文档ID中的数组中删除条目
问题描述
我有一个这样的项目架构
const projectSchema = new mongoose.Schema({
name: {
type: String,
required: true,
minlength: 2,
maxlength: 50
},
box: {
type: [String],
required: false,
minlength: 0,
maxlength: 255
},
isActive: Boolean
});
我需要从不同的文档中删除olibox的条目
例如:
如果我有 4 个不同的projectSchema
ID,并且我想olibox
从这 4 个 projectSchemas 中删除 2 个特定的 ID。我该怎么做呢?
对于一个文档,我这样做是为了删除一个数组元素..
project= await Project.findByIdAndUpdate(req.project._id,{$pull : {'box': req.params.oliId}},{new :true});
console.log("In post");
我可以$in
以某种方式使用它吗?
解决方案
试试看这是否有效。我希望它确实如此。
Project.updateMany(
{
_id: { $in: ['xxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxx'] }
},
{ $pull: { box: { $in: [8025, 7323] } } }
);
推荐阅读
- flutter - 如何为下拉列表中的选定项目应用填充
- python - 在 Windows x64 上的 Python 中将 numpy.int64 数据类型解释为本机 int 数据类型
- angular - “类型上不存在属性‘操作’……”createReducer() NgRx 函数中的错误
- flutter - 将列表中的字符串项与另一个字符串合并
- c# - 将 Angular 2 与 .NET Framework 一起使用
- node.js - 取决于多个并行 gulp 任务的完成情况
- asp.net-core - 使用 eureka 的服务发现在 docker 容器中不起作用
- java - 删除另一个地图中嵌套地图的值
- mysql - MySQL 唯一键不用作 SELECT 的索引
- c++ - 我们可以动态地将操作插入到我们的函数中吗?