We are going to preview Couchbase Playground Beta, an experimental project from Couchbase. With this tool, we can help developers learn NoSQL for free and play with Couchbase and SDKs (the SDK is just one of the features) like Java, NodeJS, .NET, and Python. You can use the instances provided by this service to run against in your own IDE or just use the prived web interface to modify code samples. There is much more and we will cover it all in this article

We will walk through many examples and try out some code together touring the UI and run the examples code against a live Couchbase Server container. You will not need to install Couchbase locally, and when you start a session on Couchbase Playground it will provide a container that you have access to through the website or from your own IDE.

The examples found on Couchbase Playground utilize our default travel-sample dataset.

Test-Drive Couchbase Playground Free

Let’s first cover the two modes in which the site operates.

Session-less mode:
This mode is the default and is always active until you “Start a Test-Drive” and is session-less (in regards to the database). When you hit the “Run” button underneath any code example, we will spin up a Couchbase instance in the background especially for that one code example, and return any logging into the output window any subsequent “Run” will be run against a fresh instance. This behavior means that every time you run a code example, no data will be persisted from one execution to the next.

Session mode:
If you would like to ensure data gets persisted from one execution to the next, choose “Start Test-Drive” and a custom and longer running Couchbase Server instance will be provisioned for your use in the cloud, you will also receive credentials allowing you to use our web console or to plug into your own code running in your own environment. These credentials are good for 35 mins. This is perfect for demonstrating Couchbase to a friend, co-worker or boss.

Screenshot of Start Test-Drive allowing for persistent data in session mode
Clicking on Start Test-Drive will enable session mode.

We are going to work in session mode, click on and you are ready to start running the existing examples or modifying them to write your own code to run against the instance. We will also review how to run code examples in your own coding environment. The connection snippets found just below the server details are examples of how to connect to this Couchbase server from any environment.

Screenshot of session information
You will find all session information in this panel

Note: This test-drive session is active for 40 mins. If you do get logged out, you will be prompted to start a new test-drive and you can log right back in. Data will be lost from the last session. The URL and unique hash values provided for username and password will change from one test-drive to the next.

Accessing Couchbase Server’s Web Console

Once a test-drive has been started, you can use the username and password shown below to access the Couchbase Web UI located at the custom URL. Click on the “Web-Admin UI” link and open in a new tab or window as you will be prompted for the username and password and will need to copy that information over manually.

Screenshot of the Couchbase Server Web Console login.
Ensure you use the credentials from your session to log in here

Once logged in you will be redirected to the Couchbase Server Dashboard and you will see your sample buckets ready to work with!

Screenshot of the bucket view in the Couchbase Server Web Console.
Bucket view in the Couchbase Server Web Console

Most Couchbase services are available in this test-drive instance: Query, Indexes, and Search are available. Analytics and Eventing are not available as these are more complex features that do not lend themselves well to a time-restricted session. As the tool matures and we make more things available these options may become available.

All prebuilt examples on Couchbase.live use the travel-sample data set, however; you can create your bucket in the web console if needed. In the Web Console, you can add your own bucket if needed and import your own documents. The Web Console can be used on its own as long as the session is running and most operations can be achieved through running N1QL queries to insert, update, and query data and more all from the Query tab.

You can try out N1QL queries in the Query Editor

N1QL query used above:

Running Couchbase Playground Examples

Back on the Couchbase.live site, click on the “KV Get” example in the NodeJS category.

Screenshot of NodeJS "KV Get" code example

When you hit the Run button, a response will show up in the Output panel on the right side of the screen. This example will generate the following in the Output Panel:

As we can see, we have retrieved one document with the key of airline_10, notice that if you change the key on line 20 to something else like: airline_112 and Run again, a new result will show in the Output:

So we can update any of the examples with whatever code we want. This creates a nice playground experience to test out samples from the Couchbase documentation. Each category of examples is a different SDK language and has similar examples. This makes it easy to compare each example highlighting a particular operation in each SDK.

Below is an example of the “Sub-document Mutate” which uses both the Lookup and Mutate methods. This example mutates just one portion of a document (country field) and in the same example retrieves that sub-document value after the mutation and prints the new value: “Canada” (shown below).

Screenshot of the result of our sub-document mutate code example

Connecting From a Local IDE

I will show you how to connect to a Couchbase.live session instance from code running on your own machine.

To create a local code example on your own machine, I suggest following one of our NodeJS Getting Started tutorials (or choose one of our other SDK’s if you like) from there it’s fairly easy to update your connection using the credentials from Couchbase Playground Beta.

Below is how I updated the couchbase.Cluster() method to use our Couchbase Playground credentials instead.

We need feedback and ideas from users to help us understand how a tool like this could help you. Feel free to reach out to us on Twitter, our DM’s are always open, and let us know what you think. My name is Eric Bishard also known as @httpJunkie on Twitter or you could reach out to our @couchbaseDev account and ask us any questions you have related to developer experience at Couchbase.

Author

Posted by Eric Bishard

International speaker, blogging and advocating for the JavaScript, React, GraphQL and NoSQL community working as a Senior Developer Advocate for Couchbase.

Leave a reply