I have this data structure
{ { "_id" : "628073739057102858", "company" : { "name" : "Unnamed Company", "funds" : 10000, "employees" : [ { "name" : "Owen", "gender" : "Male", "pay" : 1378, "trait" : "Independent", "ips" : "14.0", "sales" : 0 } ], "stats" : { "max_employees" : 2, "experience" : 0, "totalincome" : 0, "sales" : 0 }, }, "__v" : 0
}
I was wonder how I could access the object inside of employees, such as Owen and set one of it’s properties.
For example I would like to set his sales
properties to a different value, maybe something like 5.
Normally if this was in code I would just loop through the employees array to find the object property, for example:
employees.forEach( person => { if (person.name == "Owen"){ // Do Something } })
However I have no clue how to achieve this as a MongoDB function. As normal I tried code snippets from stack-overflow and tried to skim through the documentation however I don’t seem to have any luck. Any help would be much appreciated.