Connecting to Your Database

    Connecting to your trial cluster will provide you with programmatic and application-level access to its data.

    Essential Steps

    Connecting to your Capella trial cluster will allow you to access our pre-loaded travel-sample dataset or load your own data. For more information on the travel-sample dataset, visit the Travel App Data Model page.

    Creating Database Credentials

    To connect your IDE or external application to Capella, you must define at least one set of database credentials.

    Remember that database credentials are different from Capella users and their roles. While users allow you to log into the Couchbase Capella UI and manage Capella features, database credentials are only for reading or writing bucket data using the Couchbase SDK and other supported tools.
    Step 1
    1. On the left side of the page, click the Clusters tab.

    2. Click your cluster name.

    3. With the cluster now open, click the Connect tab.

    4. Scroll to Database Access and click the Manage Credentials link.

      This action opens the Database Credentials screen, which lists any existing database credentials and allows you to create new ones.

      "The 'Database Credentials' screen with no existing credentials.
    Step 2
    1. Click the Create Database Credentials on the right.

      This action opens the Create Database Credentials fly-out menu.

    2. Enter a username and password.

    3. Choose All Buckets, All Scopes, and Read/Write.

    4. Click Create.

    See Also
    For more information about database credentials and how to manage them, see Configure Database Credentials.

    Allowed IP Addresses

    You must add your own IP address to connect to your cluster.

    Step 1
    1. From the Database Credentials screen, click on the Back button.

    2. In the Connection section, select Manage Allowed IP.

    3. Click Add Allowed IP.

      The Allowed IP screen will now be shown.

      The 'Allowed IP' screen with no allowed IPs.
    Step 2
    1. For this exercise, choose the Add Permanent IP block.

    2. Beside the IP Address/CIDR Block field, click Add My IP.

    3. Your current IP address will automatically fill the IP Address/CIDR Block field.

    4. (Optional) Add a descriptive comment.

    5. Click the Add IP button.

    Your IP address is saved as an Allowed IP for connecting to your cluster.

    See Also
    For more information about configuring and managing allowed IPs, see Configure Allowed IP Addresses.

    Connecting to Capella Using SDKs

    Couchbase services are exposed through the SDK. Whether you are writing key-value applications or querying via N1QL, Couchbase’s SQL language.

    Couchbase SDKs are available for developers to access clusters using their favorite IDE. For more information on SDKs, see SDKs & Connectors.

    SDK Code Examples

    Head back to the Capella UI and the Cluster section, Connect tab:

    1. Click on the SDK Examples link.

      This action opens the SDK Examples fly-out menu.

    2. Check out the samples for Java, Go, .NET, Node.js, PHP, Python, Scala, Ruby, and Kotlin.

      The 'SDK Examples' fly-out menu open to the Java SDK example.
    3. Copy and paste a sample into your IDE.

    4. Replace username and password with your new database credentials.

    5. For bucketName, replace the entry with travel-sample.

    From your IDE you should now be able to connect, create a JSON document, and run a Couchbase N1QL query.

    See Also
    For more information about Couchbase SDKs, see SDKs & Connectors and the SDK section of our Developer Tutorials, which include tutorials on building sample applications.

    Add Your Data (Optional)

    To load your own data into Capella, do the following.

    1. Within your Cluster section of the UI, click Tools  Import.

      The Import screen will now be shown.

      "The `Import` screen with no custom imports.
    2. Near the top of the screen, click Import.

      The Import Documents fly-out menu can walk you through all the steps to import JSON or CSV data to your database.

    If you load data into a new bucket you have created, you will need to build an index before performing a N1QL query. (A primary index is the simplest, but not recommended for production environments.)

    Do this:

    1. Go to the Query Workbench (Within Cluster, Tools).

    2. Near Settings, leave "Select a bucket" as is. Make no change.

    3. Execute "CREATE PRIMARY INDEX ON bucketName" (replace with correct name).

    Learn more about the Index Service in the documentation.

    See Also
    For more information on importing data to Couchbase Capella, see Import Data.

    Next Steps

    The next step is to query your data — using our SQL-based querying language.