I need to update (append) an array in a document which in some situations is not created yet. If Is missing should create it first before updating. Is there a way to do this in a single operation?
Now I am doing something like this:
- check if document exists
- if document exists → update
- if document doesn’t exist → create
The problem I have is that in a situation with high concurrency between the moment in which I check if the document exists and update or insert, the status of the document may change (like the document could be created by another worker, or could be deleted by another worker)
What is the best approach to do this?
btw, I am using PHP