Introduction

Couchbase is excited to announce a new product feature of Collections as part of its beta release 7.0 and support for collections has been extended to Analytics Service as well. Collections and scopes are logical containers within a bucket. A collection is a data container within a bucket. A scope is a mechanism for grouping multiple collections within a bucket. Collections allow users to group related data – much like tables in relational databases. For more information on collections, scope, and specific use cases, please read the blog here

How do Collections work in the Analytics Service?

Before digging into how Collections work in Analytics, let’s understand how collections work in the Data Service. Let’s start with a simple illustration of an existing set of Couchbase Collections in the travel industry that involves airlines and hotel bookings. We have a bucket named travel (similar to databases in RDBMS), with a scope called inventory (similar to schemas in RDBMS) and 4 collections of airlines, airports, routes, and hotels (similar to tables in RDBMS). See visual diagram A below:

Bucket Scope Collection

Diagram B below is a good visual representation of how collections in the data service would look like in the Analytics service 

For Analytics Service to be able to use these collections (in our example let’s say we want to use Hotel collections to be enabled). There are multiple options to enable the collections using these analytics data definition languages (DDLs) in the Analytics workbench:

  1. Leverage 6.x statements for users familiar with Analytics service to create Hotel collection above. These statements are supported in release 7.0 as well
    •  Create a dataverse/namespace using the following
      • CREATE DATAVERSE `travel-sample`.inventory;
    • Create hotel collection using the following statement: 
      • CREATE DATASET `travel-sample`.inventory.hotel ON `travel-sample`.inventory.hotel;

2.  ALTER COLLECTION `travel-sample`.inventory.hotel ENABLE ANALYTICS;

    • The ENABLE option creates an analytics namespace or dataverse called travel-sample.inventory if one does not exist already
    • Analytics collection or dataset in the above namespace: hotel

3.  CREATE ANALYTICS COLLECTION `travel-sample`.inventory.hotel ON `travel-sample`.inventory.hotel;

    • This statement assumes that dataverse travel-sample.inventory is already in place. If not, you can create one as mentioned in option #1 above. Also, we support a new DDL below which creates a dataverse using scope nomenclature:
      • CREATE ANALYTICS SCOPE `travel-sample`.inventory;
    • Once the create analytics collection statement above is executed, the hotel collection is created as well.

Collections terminology in 6.x 

Analytics services have the following key concepts that are used in 6.x releases:

Dataverses: is short for data universe, a top-level organizing concept and a namespace for other metadata entities (links, buckets, datasets, indexes, etc). There is one Default dataverse that is available without creating it and that cannot be deleted

Datasets: are containers that hold JSON objects, linked to underlying collections. As you can imagine, the new collections feature fits very well with Analytics datasets, in fact, datasets as synonymous with collections.

Summary

 Collections are very easy to use in the Analytics Service. They align with N1QL collection naming conventions to refer to collections, scope, and buckets so that queries can be used interchangeably between the Query and Analytics engines. To ensure backward compatibility with 6.x releases, the Analytics service continues to support DDL statements to create and manage dataverse and datasets.

Next Steps

I hope you are excited about this new functionality of Scopes and Collections from Couchbase. Below is a list of resources for you to get started and we look forward to your feedback on Couchbase Forums.

Documentation 

What’s new

Release notes

Get the Beta

Download

Author

Spread the love

Author

Posted by james.oquendo

Couchbase team member

Leave a reply