-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use cosmos client directly along with spring data repository as I could not find few operations like partial updates in spring data cosmos #32390
Comments
Hi, @arunim29 Thanks for reaching out. For example: @SpringBootApplication
public class SampleApplication implements CommandLineRunner {
private XxxRepository repository;
private CosmosAsyncClient client;
public SampleApplication(XxxRepository repository, CosmosAsyncClient client){
this.repository= repository;
this.client= client;
}
} |
@arunim29 what @chenrujun mentioned is absolutely correct. However, I would like to know your use case of Patch API in Spring and how / why do you plan to use this feature. Since we are planning on developing Patch API support in spring-data-cosmos SDK, it would really help us to know how our customers plan to use this feature. @TheovanKraay / @trande4884 - please take this discussion forward, thanks! |
@arunim29 + @chenrujun we plan to expose patch something like the below. Let us know if this is not what you expect. Feel free to make suggestions or ask questions here. CosmosPatchOperations patchOperations = CosmosPatchOperations
.create()
.replace("/size", 5)
.add("/color", "blue");
User patchedUser = userRepository.save(user,patchOperations,null); |
@kushagraThapar I was on vacation. Hence, could not reply. So, my usecase is pretty straight-forward. I have a bunch of fields in my document but in one of the heavily used apis of my service, I only need to update one field. Hence, I do not want to first fetch the document and then update it. It will be a waste of resources. |
@TheovanKraay what is the user in userRepository.save(user,patchOperations,null) ? In patched operations, we are not expected to pass any existing object. Also, what is this null param? |
@TheovanKraay I had a look at ur PR for this feature and understand now that null represents CosmosPatchItemRequestOptions. This is fine. BUT I have a concern in this method signature. Here in the userRepository.save(user,patchOperations,null) , my assumption is that you are expecting caller to create a User object with just id and pk set right? If that is the case, what if the user has added jackson annotations in this POJO which prevent non-nulls values for some fields? Will u just get id and pk and ignore rest of the POJO? |
Yes that’s correct. Caller may pass the whole object if it’s available, or they can set only id and pk if they prefer. Either way only id and pk will be used from the object passed. Only the values defined in patchOperations are the ones that will actually be patched. |
@arunim29 in light of this discussion, we're making changes to avoid the confusion you ran into. Caller will now pass id + partition key of the entity to be patched, along with it's domainType, and the intended patchOperations: CosmosPatchOperations patchOperations = CosmosPatchOperations
.create()
.replace("/size", 5)
.add("/color", "blue");
User patchedUser = userRepository.save(user.getId(), new PartitionKey(user.getLastName()), User.class, patchOperations); |
See PR for patch: #32630 |
This has been implemented, closing it. |
Query/Question
I am trying to use spring data cosmos in my project. But some operations which I need I could not find in spring data cosmos. For eg., partial updates, do only an insert (not upsert), do only an update (not upsert).
So, I was thinking of using cosmosclient of cosmos sdk directly. Is there a way to use cosmosclient along with spring data cosmos such that both use the same cosmosclient instance?
Why is this not a Bug or a feature Request?
This is not a bug/feature request. I want to use the convenience of spring data for GET queries along with flexibility cosmosclient provides for some other operations.
Setup (please complete the following information if applicable):
Library: (com.azure:azure-spring-data-cosmos:3.30.3)]
The text was updated successfully, but these errors were encountered: