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?

0

1 Answer 1

0

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

Project.updateMany(
  {
    _id: { $in: ['xxxxxxxxxxxxxxxxxxxxxxx', 'xxxxxxxxxxxxxxxxxxxxxxx'] }
  },
  { $pull: { box: { $in: [8025, 7323] } } }
);
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.