This guide provides step-by-step instructions for configuring a Couchbase Capella App Services instance, which the mobile application will utilize to store and retrieve data from the cloud.
Follow the full set of directions for setting up a free account.
In these directions, we will create a new Bucket, Scope, and Collection for storing data. When you log into Capella you should be at the Operational Cluster tab. Click on cluster listed in the provided cluster listing. The Home tab will appear and a listing of options should be presented.
Click on the Data Tools tab. Once there, click the "+ Create" button on the left side of the navigation menu to create a new Scope and Collection.
The "Create a Bucket, Scope, and Collection" dialog will appear. Enter the following information:
-
Select "New" and enter a bucket name in in the New Bucket Name field. For example, enter
Todo
-
For Scope, select New and enter the name of
data
-
For Collection, select New and enter the name
tasks
Click the Create button to create the new Scope and Collection.
Once you have followed the directions for setting up your bucket, follow the directions for setting up App Services.
Click the App Services tab and select your created App Service from the Setup App Service Instance step. The App Endpoints listing should appear. Click on the + Create App Endpoint to create a new endpoint.
When the Create App Endpoint screen appears enter the following information based on the new bucket you created above:
- For the Name field enter
tasks
- For the Bucket, select
Todo
- For the Scope, select
data
- Under "Choose collections to link", select the Link option for the
tasks
collection
Click the Create button to create the new App Endpoint. Note it may take a few minutes for your App Endpoint to be created.
The Access Control and Data Validation is used to setup access control policies for the App Endpoint. In the case of the app, script specifies the policies to ensure that only the task owner can update corresponding task, while allowing a user to read all tasks.
From the App Endpoints list, click on your newly created App Endpoint tasks
. From the Access Control and Validation screen, click the linked collections tasks
. Follow the following steps:
- Click the Import from File button.
- Browse to the repo where you downloaded the code and select the sync.js file located in the root of the project. Click the Import button to import the Sync Function.
- Click the Save button to save the Sync Function.
- Once the alert is displayed that the Sync Function was saved, click the Settings tab.
- Click the
Resume App Endpoint
button under the Resume App Endpoint section.
This script achieves the business rule that only users that own a document can modify it checking the ownerId field and use the requireUser function to deny writes from other users. This helps secure the data from bugs in the application and validate that writes are only performed by the owner of the task.
Click on the Security tab. Now click on the App Users tab from the navigation menu on the left and then click the "+ Create App Users" button.
Enter the following information:
- For the App User Name enter:
demo1@example.com
- For the App User Password enter:
P@ssw0rd12
Click the "Create App User" button to create the App User. Follow these steps to create a second App User with the following information:
- For the App User Name enter:
demo2@example.com
- For the App User Password enter:
P@ssw0rd12
Warning
The password is set to P@ssw0rd12
for demonstration purposes. This password is in this document, which means anyone on the internet will know it. You should use a more secure password for your application.
From the App Endpoints section, click on the Connect tab. The Connect Information screen will appear.
Copy the Public Connection URL that is provided. This will be used in the mobile application to connect to the App Endpoint.
Now open the capellaConfig.plist
file, which is located in the App folder.
Update the endpointUrl
value with the Public Connection URL you copied from the App Endpoint.