0
{
  _id: 1,
  name: 'Some event',
  items: [{
     status: 'NEW',
     value: 'one'
  },{
     status: 'NEW',
     value: 'two'
  }]
}

I need to update each status to the PENDING

This is doesn't work(

findOneAndUpdate({ _id: event.id },
{
 $set: {
   'items.$.status': "PENDING",
 },
},
{
  new: true,
  upsert: true,
}),

The main idea that i need to update each status field without any conditions because I already have the needed item and it just update status before next action.

Igor Zinchenko
  • 305
  • 3
  • 13

1 Answers1

0

you can apply $ reference for all the elements by $[], try 'items.$[].status': "PENDING",

Thanks @turivishal!

Igor Zinchenko
  • 305
  • 3
  • 13