Spring Data Couchbase (2.x) Document Relation

2019-09-16 05:13发布

问题:

I want to ask about spring data couchbase 2.x

Can I refer a document in spring data couchbase like @DbRef annotation in spring data mongodb?

回答1:

we implemented our persistence with mongo initially and are in the mode of switching to couchbase. Doing so, we're finding that referencing is highly relying on DBRef from mongo to perform relationships. This should be abstracted away and implemented outside of the underlying implementation. Same goes for searching, indexing, and the like.

https://jira.spring.io/plugins/servlet/mobile#issue/DATAREST-326

Spring Data has an @Reference which indeed is evaluated by the metadata and @DBRef carries it for mongodb.

Example :

Author.java

@Document
public class Author {

    @Field
    private String name;
}

Book.java

@Document
public class Book {

    @Field
    private String title;

    @Reference
    private Author author;
}


Sample code for @Reference using simpledb https://github.com/3pillarlabs/spring-data-simpledb#reference