0

I have a project Schema like this

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
});

And I need to delete the entry of olibox from different documents

For example:

If I have 4 different projectSchema IDs and I want to delete 2 specific olibox IDs from these 4 projectSchemas..how can i dot that?

For one single document I am doing like this to delete one array element..

project= await Project.findByIdAndUpdate(req.project._id,{$pull :  {'box': req.params.oliId}},{new :true});


console.log("In post"); 

Can I use $in with it somehow?

M.K
  • 1,464
  • 2
  • 24
  • 46
Hsn
  • 1,168
  • 2
  • 16
  • 39

1 Answers1

0

Try and see if this works. I am hoping it does.

Project.updateMany(
  {
    _id: { $in: ['xxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxx'] }
  },
  { $pull: { box: { $in: [8025, 7323] } } }
);
PrivateOmega
  • 2,509
  • 1
  • 17
  • 27