Reputation: 123
I am using mongodb for a java application and trying to use spring data repository to update the document. I use the @Query annotation like this: @Query("{ 'username' : ?0 }, { $set : { 'age' : ?1}}") void updateAgeByUserName(String username, int age);
But this doesn't work. I know the save will update the whole thing but I just want to update the age field using update query. How can I do this?
Appreciate any help.
Upvotes: 2
Views: 2143
Reputation: 2606
Spring-data is a framework for general purpose that provides a very basic support to CRUD operations. If you need complex operations, like update using any $operator
, you'll need to implement a custom repository to it.
Upvotes: 5