Skip to content

Commit f1575d0

Browse files
committed
Add Collections to Reference Documentation. (#1296)
Closes #1295.
1 parent 0473291 commit f1575d0

File tree

2 files changed

+84
-4
lines changed

2 files changed

+84
-4
lines changed

src/main/asciidoc/collections.adoc

+80
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
[[couchbase.collections]]
2+
= Collection Support
3+
4+
Couchbase supports https://docs.couchbase.com/server/current/learn/data/scopes-and-collections.html[Scopes and Collections]. This section documents on how to use it with Spring Data Couchbase.
5+
6+
The https://github.com/couchbaselabs/try-cb-spring[try-cb-spring] sample application is a working example of using Scopes and Collections in Spring Data Couchbase.
7+
8+
The 2021 Couchbase Connect presentation on Collections in Spring Data can be found at https://www.youtube.com/watch?v=MrplTeEFItk[Presentation Only] and https://web.cvent.com/hub/events/1dce8283-986d-4de9-8368-94c98f60df01/sessions/9ee89a85-833c-4e0c-81b0-807864fa351b?goBackHref=%2Fevents%2F1dce8283-986d-4de9-8368-94c98f60df01%2Fsessions&goBackName=Add%2FView+Sessions&goBackTab=all[Presentation with Slide Deck]
9+
10+
== Requirements
11+
12+
- Couchbase Server 7.0 or above.
13+
- Spring Data Couchbase 4.3.1 or above.
14+
15+
== Getting Started & Configuration
16+
17+
18+
=== Scope and Collection Specification
19+
There are several mechanisms of specifying scopes and collections, and these may be combined, or one mechanism may override another.
20+
First some definitions for scopes and collections. An unspecified scope indicates that the default scope is to be used, likewise, an
21+
unspecified collection indicates that the default collection is to be used.
22+
There are only three combinations of scopes and collections that are valid. (1) the default scope and the default collection; (2) the default
23+
scope and a non-default collection; and (3) a non-default scope and a non-default collection. It is not possible to have a non-default
24+
scope and a default collection as non-default scopes do not contain a default collections, neither can one be created.
25+
26+
A scope can be specified in the configuration:
27+
[source,java]
28+
----
29+
@Configuration
30+
static class Config extends AbstractCouchbaseConfiguration {
31+
32+
// Usual Setup
33+
@Override public String getConnectionString() { /* ... */ }
34+
35+
// optionally specify the scope in the Configuration
36+
@Override
37+
protected String getScopeName() {
38+
return "myScope"; // or a variable etc.;
39+
}
40+
41+
}
42+
----
43+
Scopes and Collections can be specified as annotations on entity classes and repositories:
44+
[source,java]
45+
----
46+
@Document
47+
@Scope("travel")
48+
@Collection("airport")
49+
public class Airport {...
50+
----
51+
52+
[source,java]
53+
----
54+
@Scope("travel")
55+
@Collection("airport")
56+
public interface AirportRepository extends CouchbaseRepository<Airport, String> ...
57+
----
58+
59+
Scopes and Collections can be specified on templates using the inScope(scopeName) and inCollection(collectionName) fluent APIs:
60+
[source,java]
61+
----
62+
List<Airport> airports = template.findByQuery(Airport.class).inScope("archived").all()
63+
----
64+
65+
Scopes and Collections can be specified on repositories that extend DynamicProxyable using the withScope(scopeName) and withCollection(collectionName) APIs:
66+
[source,java]
67+
----
68+
public interface AirportRepository extends CouchbaseRepository<Airport, String>, DynamicProxyable<AirportRepository>{...}
69+
...
70+
List<Airport> airports = airportRepository.withScope("archived").findByName(iata);
71+
----
72+
73+
.The order of precedence is:
74+
. inScope()/inCollection() of the template fluent api
75+
. withScope()/withCollection() of the template/repository object
76+
. annotation of the repository method
77+
. annotation of the repository interface
78+
. annotation of the entity object
79+
. getScope() of the configuration
80+

src/main/asciidoc/index.adoc

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
= Spring Data Couchbase - Reference Documentation
2-
Michael Nitschinger, Oliver Gierke, Simon Baslé
2+
Michael Nitschinger, Oliver Gierke, Simon Baslé, Michael Reiche
33
:revnumber: {version}
44
:revdate: {localdate}
55
:spring-data-commons-docs: ../../../../spring-data-commons/src/main/asciidoc
66

7-
(C) 2014-2019 The original author(s).
7+
(C) 2014-2022 The original author(s).
88

99
NOTE: Copies of this document may be made for your own use and for distribution to others, provided that you do not charge any fee for such copies and further provided that each copy contains this Copyright Notice, whether distributed in print or electronically.
1010

@@ -24,8 +24,8 @@ include::repository.adoc[]
2424
include::reactiverepository.adoc[]
2525
include::template.adoc[]
2626
include::transactions.adoc[]
27-
// (daschl) disabled the ansijoins docs since it is being overhauled for 4.x
28-
// include::ansijoins.adoc[]
27+
include::collections.adoc[]
28+
include::ansijoins.adoc[]
2929
:leveloffset: -1
3030

3131
[[appendix]]

0 commit comments

Comments
 (0)