Skip to content

Support of the Sub-Document operations #1659

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

Closed
babltiga opened this issue Jan 31, 2023 · 3 comments · Fixed by #1660
Closed

Support of the Sub-Document operations #1659

babltiga opened this issue Jan 31, 2023 · 3 comments · Fixed by #1660
Labels
type: enhancement A general enhancement

Comments

@babltiga
Copy link
Contributor

Are there any plans to support the Sub-Document operations? In most of cases, the updates on the documents are partial so users can benefit from using Sub-Document mutations.

So something like this can be achieved without using Collections directly.

@Repository
public interface AirlineRepository extends CouchbaseRepository<Airline, String> {
	@MutateOnly({"name"})
	void upsert(Airline airline);

}

which is equivalent of

couchbaseTemplate.getCollection("airline")
     .mutateIn(airline.getId(), Collections.singletonList(upsert("name", airline.getName())));
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jan 31, 2023
@mikereiche
Copy link
Collaborator

Subdocument support is a known outage, but this is the first request for it. In #1310, @jorgerod said he had "The operations that I have added are, for example, the saving with the possibility of the insertById, operations to work the api of subdocuments", but hasn't shared that.

@mikereiche mikereiche added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Feb 1, 2023
@babltiga
Copy link
Contributor Author

babltiga commented Feb 1, 2023

I'm ready to work on this if we of course agree on the API )

@mikereiche
Copy link
Collaborator

mikereiche commented Feb 2, 2023

Let's see - the possibilities for subdocuments is https://docs.couchbase.com/java-sdk/current/howtos/subdocument-operations.html. Let's ignore the counter and binary (append, prepend), and array append/prepend functions for now.

For new stuff, we usually first put it in the template, and then figure out how to call it from the repository.

For the template: findById().project( String[] propertyNames ) already uses the subdocument api lookUpIn (indirectly, through the java sdk get() method). It might make sense to add similar methods - insert(), upsert(), replace() and remove() methods to upsertById() and replaceById(). (an alternative would be to create a new mutateById() operation -

insert() can go on either replaceById() or upsertById(), the specified field must not exist:

template.replaceById(Airline.class).insert({"name", "address"}).one(someAirline) // replaceById does CAS

template.upsertById(Airline.class).insert({"name", "address"}).one(someAirline) // upsertById does not do CAS

replace() can go on either replaceById() or upsertById(), the specified field must exist :

template.replaceById(Airline.class).replace({"name", "address"}).one(someAirline) // replaceById does CAS

template.upsertById(Airline.class).replace({"name", "address"}).one(someAirline) // upsertById does not do CAS

upsert() can go on either replaceById() or upsertById()

template.replaceById(Airline.class).upsert({"name", "address"}).one(someAirline) // replaceById does CAS

template.upsertById(Airline.class).upsert({"name", "address"}).one(someAirline) // upsertById does not do CAS

remove() needs only the id - it doesn't need the object for values - it is just remove properties. If it has the object it can do CAS.

template.replaceById(Airline.class).remove({"name", "address"}).one(someAirline) // replaceById does CAS, needs airline object

template.upsertById(Airline.class).remove({"name", "address"}).one(id) // upsertById does not do CAS, does not need airline object

When that is available in the template, then it can be called in a repository method :

  public void upsert(T airline, String[] propertyPaths){
      template.upsertById(T).upsert(propertyPaths).one(airline);
  }

babltiga added a commit to babltiga/spring-data-couchbase that referenced this issue Feb 3, 2023
mikereiche pushed a commit that referenced this issue Feb 3, 2023
@mikereiche mikereiche added this to the 5.0.2 (2022.0.2) milestone Feb 4, 2023
mikereiche pushed a commit that referenced this issue Feb 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants