A newer version of this documentation is available.

View Latest

Database Configuration

      +

      Using Sync Gateway’s Admin REST API to configure and manage databases

      Pre-3.0 Legacy Configuration Equivalents

      This content describes configuration for Sync Gateway 3.0 and higher — for legacy configuration, see: Legacy Pre-3.0 Configuration

      Introduction

      From Sync Gateway 3.0 you can use the Admin REST API to provision persistent configuration changes. This content introduces the Create Database and Configure Database endpoints for convenience — see Database Configuration for a full description of the endpoints available.

      Create Database

      PUT {url}/{dbname}/

      Use this method to create a new Sync Gateway database.

      The database name is taken from the URL path. Pass the required database configuration settings as a JSON object in the request body.

      {
          "name": "todo_db"
          "bucket": "todo_app"
      }

      By default the created database is brought online immediately, unless you include "offline": true in the configuration.

      Sync Gateway Roles Required (CBS 7.0.2 Developer Preview):

      • Sync Gateway Architect

      Parameters

      Type Name Description Schema

      Path

      db
      required

      Database name

      string

      Body

      database configuration details
      optional

      Provision the database configuration details as JSON object in request body

      Database_model

      Responses

      HTTP Code Description Schema

      201

      201 - OK - Create Operation successful

      No Content

      401

      401 - Unauthorized - Error validating credentials

      No Content

      Example

      Example 1. Create database

      Here we create a new sync gateway database.

      • Curl

      • HTTP

      curl --location --request PUT 'http://127.0.0.1:4985/traveldb/' \ (1)
      --header 'Authorization: Basic c3luY19nYXRld2F5OnBhc3N3b3Jk' \ (2)
      --header 'Content-Type: application/json' \
      --data-raw '{
      "bucket": "todo", (3)
      "num_index_replicas": 0}'
      PUT /traveldb/ HTTP/1.1 (1)
      Host: 127.0.0.1:4985
      Authorization: Basic c3luY19nYXRld2F5OnBhc3N3b3Jk (2)
      Content-Type: application/json
      Content-Length: 44
      
      {
      "bucket": "todo", (3)
      "num_index_replicas": 0}
      1 Here we create a sync gateway database called traveldb
      2 Note we are using Basic Authentication here to authenticate against an existing Couchbase Server RBAC user
      3 Here we point to the Couchbase Server bucket called todo

      Configure Database

      PUT {url}/{db}/_config

      Use this endpoint to update the configuration of an existing Sync Gateway database.

      Provide the database name in the URL path. Provide the required database configuration settings as a JSON object in the request body.

      By default the updated database is brought online immediately, unless you include "offline": true in the configuration.

      Sync Gateway Roles Required (CBS 7.0.2 Developer Preview):

      • Sync Gateway Architect

      • Sync Gateway Application

      Parameters

      Type Name Description Schema

      Path

      db
      required

      Database name

      string

      Body

      database configuration details
      optional

      Provision the database configuration details as JSON object in request body

      Database_model

      Responses

      HTTP Code Description Schema

      200

      200 - OK - Operation successful

      No Content

      401

      401 - Unauthorized - Error validating credentials

      No Content

      Example

      Example 2. Configure database

      Here we configure an existing sync gateway database.

      • Curl

      • HTTP

      curl --location --request PUT 'http://127.0.0.1:4985/traveldb/_config/' \ (1)
      --header 'Authorization: Basic c3luY19nYXRld2F5OnBhc3N3b3Jk' \ (2)
      --header 'Content-Type: application/json' \
      --data-raw '{
        "enable_shared_bucket_access": true,
        "import_docs": true
      }' (3)
      PUT /traveldb/_config/ HTTP/1.1  (1)
      Host: 127.0.0.1:4985
      Authorization: Basic c3luY19nYXRld2F5OnBhc3N3b3Jk  (2)
      Content-Type: application/json
      Content-Length: 120
      
      {
      "enable_shared_bucket_access": true,
      "import_docs": true
      } (3)
      1 Here we choose to configure (_config) a sync gateway database called traveldb
      2 Note we are using Basic Authentication here to authenticate against an existing Couchbase Server RBAC user
      3 Here we toggle a couple of database properties

      Schema

      This section shows Sync Gateway’s database configuration settings in schema format for convenience in constructing JSON models for use in the Admin REST API.

      The configuration settings described here are provisioned through the Database Configuration endpoints.