I have in my project a component with a button that creates a document in my firestore database saving several values:
- The userID of the user.
- Specific documentKey of the document that the user has been working on.
- User’s email.
- Current date.
- Obtained score in the document.
All of these are values are automatically stored under an aleatory documentKey.
Everything works great, but I have one thing that I would like to improve. Everytime that the user clicks the button, a new document is created in the database, but it wouldn’t be necessary to create a new one always. I would like that if there is an existing document with the same userID, documentKey but a diferent score, that by clicking the button instead of creating a new registry, that the existing score value would be set to the higher value.
The idea is to keep just the higher value in the score field for the given user and documentKey. Would that be possible? Here it is a screenshot of the datasheet where the values are stored.