Implement the Data Model
- tutorial
Create a cluster and use buckets, scopes, and collections to partition your data.
Buckets, Scopes, and Collections
To organize and manage your data in Couchbase, you can create buckets, scopes, and collections inside your cluster.
A bucket is equivalent to a database in a relational database management system, while scopes and collections are used to provide separation between documents of different types. A bucket can hold any number of scopes, and a scope can hold any number of collections.
bucket |
Stores and retrieves data in the server. |
scope |
Stores collections. When you create a new bucket, Couchbase provides you with a default scope called |
collection |
Contains a set of documents. Couchbase provides you with a default collection called |
To continue this tutorial, you must create a bucket to hold all student data, a scope to narrow down the data into only data related to an art school, and two collections to narrow it down further into art school students and art school courses.
For more information about buckets, scopes, and collections, see Buckets, Scopes, and Collections in the Capella documentation.
Create a Bucket
To create a bucket:
-
In the Couchbase Web Console, go to Buckets.
-
Click Add Bucket.
-
For the bucket name, enter
student-bucket
. -
Click Add Bucket to create your bucket.
Create a Scope
To create a scope:
-
In the list of buckets, next to
student-bucket
, click Scopes & Collections. -
Click Add Scope.
-
For the scope name, enter
art-school-scope
. -
Click Save to create your scope.
Create Collections
For this tutorial, create two collections: one to store student records, and one to store course details.
To create a collection:
-
In the list of scopes and collections, next to
art-school-scope
, click Add Collection. -
Click Add Collection next to
art-school-scope
. -
For the scope name, enter
student-record-collection
. -
Click Save to create your first collection.
To create the second collection, follow the previous steps but name the collection course-record-collection
.
The two collections allow you to use the relational model and the document model at the same time to achieve the best design and performance possible.
The student-record-collection
contains student records, and each student record contains a list of that student’s enrollments.
Unlike the standard relational model decomposition where a link table is created between students and courses, a document model stores the enrollments as part of the student records.
The course-record-collection
, on the other hand, uses the relational model to link the enrollment records to the course records they apply to.
This allows you to retrieve other details like the full title of the course or the number of credits students receive upon completing the course.
Next Steps
After implementing the data model, you can set up a Couchbase SDK and connect it to your cluster to write your first application.