Q1 : Yes, you can pass PartialUser.class
to the Repository.save()
method. However, it's essential to understand that the PartialUser
class you are creating is a partial representation of the User
document in Cosmos DB. When you pass PartialUser.class
, you are instructing the repository to treat this class as a projection of the User
document, meaning that it only contains a subset of fields present in the User
document.
In your scenario, if you only want to update myParentField.flagImPatching
, your approach to use PartialUser.class
should work correctly as long as the Cosmos DB patch operation is correctly formed. The Cosmos DB SDK is designed to work with partial document updates and will only modify the fields you specify.
Q2: Yes, you do need to supply the @Id
(document ID) and @Version
(etag) fields when performing the patch operation. Here’s why:
Document ID (@Id
): The document ID is necessary to locate the specific document within the collection that you want to update.
Etag (@Version
): The etag is used for optimistic concurrency control. Cosmos DB uses the etag to ensure that no other update has been made to the document between the time it was retrieved and the time the patch operation is applied. If the etag in the request does not match the current etag of the document in the database, the patch operation will fail to prevent conflicts.
Given your scenario, the patch operation would look something like this:
javaCopy code
CosmosPatchOperations
In this operation, you are essentially telling Cosmos DB to replace the value at /myParentField/flagImPatching
with true
. The PartialUser
object contains the required fields (userId
, _etag
) to ensure that this operation is performed on the correct document and that the update is safe in terms of concurrency.