For some reason, bulkWrite and arrayFilter are not modifying the document. MongoDB and Mongoose

Viewed 782

I have these two subdocuments that are basically structured the same. Each of these documents includes an array of objects name scheduleInfo. This array is structured like so.

EquipmentList

scheduleInfo: [{month: String, hours: Number, frequency: String, equipId: String, uniqId: String}]

AdditionalLabor

scheduleInfo: [{month: String, hours: Number, frequency: String, addLaborId: String, uniqId: String}]

This is the code I use to add objects to the scheduleInfo in the equipmentList

 OpportunityModel.bulkWrite(
  equipSch.map(d => ({
    updateOne: {
      filter: { sfOppId: oppId },
      update: {
        $set: { "equipmentList.$[e].scheduleInfo": d.equipSch }
      },
      upsert: true,
      arrayFilters: [{ "e.sfEquipId": d.equipId }]
    }
  }))
)

this code executes correctly. Since the scheduleInfo in additionalLabor is essentially the same thing, this is the code I use to add objects to the scheduleInfo in the additionalLabor

 OpportunityModel.bulkWrite(
  additionalLaborSch.map(d => ({
    updateOne: {
      filter: { sfOppId: oppId },
      update: {
        $set: { "additionalLaborCostInfo.$[e].scheduleInfo": d.schedule }
      },
      upsert: true,
      arrayFilters: [{ "e._id": d.addLaborId }]
    }
  }))

IT DOES NOT WORK I get a read out showing it found matching documents but did not modify any.

If I get rid of the list filter and use the wildcard $[] it modifies the document, but sets the same schedule for all of the additionalLabor items which is not correct. I have been staring at this code for a while now and I have no idea why it is not working. Please help!

1 Answers
Related