findAndUpdate with nested array

If anyone will search it, this is the answer:

const result = await this.companyModel.updateOne(
        { 'offers._id': new Types.ObjectId(offerId) },
        { $set: { 'offers.$[].photos.$[x].order': 0 } },
        { arrayFilters: [ { 'x._id': new Types.ObjectId(photoId) } ] }
      );
1 Like