Search code examples
spring-datacouchbasespring-data-couchbase

How to tell Spring Data Couchbase to embed or reference entity?


My question is simple: how do I tell Spring Data Couchbase to either embed or reference an entity using @Field? Is there an extra annotation to it?


Solution

  • You can't reference other documents using @Field, the goal of this annotation so far is only to specify the name of your attribute in the final JSON document, but the @Field annotation is not mandatory.

    Regarding the ID reference validation, there are a lot of side effects on adding such a feature/validation, one of them is that your write throughput will be significantly impacted. MongoDB has a Master/Slave architecture, which enables this feature to be easily implemented, on the other hand, it sacrifices scalability.

    Couchbase approach prefers to rely on your application to do such validation (it is the application responsibility to save the correct data anyways) but make your reads/writes as fast as possible.

    My Personal View: This kind of validation is just an RDBMS "bureaucracy", as your application already validates everything.