I’ve been trying to update the data in my mongoDB. I want to update all products with a new productName field.
my data looks something like:
{
    "id": "12345",
    "products": [{
        "id": 0
        "productCode": "test",
        "status": "PENDING",
    },
    {
        "id": 1
        "productCode": "test",
        "status": "COMPLETE",
    }],
}
When I try the following. I get this error The positional operator did not find the match needed from the query.
db.customers.updateMany(
  { id: "12345" },
  { $set: {
    "products.$.productName": "Name here" } 
  }
)
If I do account.0.productName then it’s fine and updates. I’m not sure why $ is not working for me
db.customers.updateMany(
  { id: "12345" },
  { $set: {
    "products.0.productName": "Name here" } 
  }
)
 
    