I've got an endpoint that takes a document ID, and the an Employee object in a nested array that I'd like to have updated. This is working fine. I tried to modify the endpoint to take more than 1 Employee and have it update them all at once, but I can't get it to work. I'm not sure if I've got the format wrong, or it's not possible.
To elaborate, my Census is an already existing object as follows, with 10 Employees in a list:
{
"id": <ID>
...
"employeeList": [
{
"employeeId": <Employee_ID>,
...
}
...
]
}
I want to update an existing Employee with some new information. So I use the mongo Document ID to find the document, and then find the correct Employee in the list by its EmployeeID. I have it working with something like this for a single Employee update:
Query query = new Query().addCriteria(new Criteria("id").is(id))
.addCriteria(new Criteria("employeeList.employeeId").is(employee.getEmployeeId());
update.set("employeeList.$", employee);
UpdateResult result = mongoTemplate.updateFirst(query, update, Census.class);
When I tried to update it to do them all at once, that didn't work. I realize now my approach doesn't really make sense so I won't post it (basically surrounding the .addCriteria and the update.set in a for loop to do it for each Employee in the provided list). Got an error like: "Due to limitations of the com.mongodb.BasicDocument, you can't add a second 'employeeList.employeeId' criteria".
Can I do it? Is the only other option to just update this document multiple times in a row? I think it's better to do that than calling the endpoint X times. I'm on Mongo 3.6 in case that affects any answers. TIA.