You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Hyperledger Composer Rest Server对接Cloudant DB的COMPOSER_DATASOURCES配置咨询

Got it, let's walk through exactly how to configure the COMPOSER_DATASOURCES environment variable to get your Hyperledger Composer Rest Server storing cards in IBM Cloudant NoSQL DB. I’ve broken this down into straightforward steps:

Step 1: Understand the COMPOSER_DATASOURCES structure

This variable uses a JSON object to define the database connector and its connection details. For Cloudant, you’ll need to specify the cloudant connector type, along with your Cloudant instance’s connection credentials and target database name.

Step 2: Gather your Cloudant connection details

First, grab these values from your IBM Cloud Cloudant service:

  • Cloudant Service URL: Found in your Cloudant instance’s "Credentials" tab (looks like https://<your-instance-id>.cloudantnosqldb.appdomain.cloud)
  • IAM API Key: If you’re using IBM IAM authentication (the default for newer Cloudant instances), generate this in the Cloudant credentials or IBM IAM console. It needs permissions to write to your target database.
  • Target Database Name: Create a new database in the Cloudant UI first (e.g., composer-cards — the rest server won’t auto-create this for you).

If you’re using legacy Cloudant authentication (username/password), you’ll instead need:

  • Cloudant username and password (from your legacy credentials)
  • The full authenticated URL (format: https://<username>:<password>@<instance-id>.cloudantnosqldb.appdomain.cloud)
Step 3: Build the COMPOSER_DATASOURCES JSON

Use one of these templates based on your authentication method:

{
  "db": {
    "name": "db",
    "connector": "cloudant",
    "url": "https://<your-instance-id>.cloudantnosqldb.appdomain.cloud",
    "database": "<your-db-name>",
    "iamApiKey": "<your-iam-api-key>",
    "iamUrl": "https://iam.cloud.ibm.com/identity/token"
  }
}

For Legacy Username/Password Authentication

{
  "db": {
    "name": "db",
    "connector": "cloudant",
    "url": "https://<your-username>:<your-password>@<your-instance-id>.cloudantnosqldb.appdomain.cloud",
    "database": "<your-db-name>"
  }
}
Step 4: Set the environment variable

How you set this depends on your operating system or deployment method:

Linux/macOS Terminal

export COMPOSER_DATASOURCES='{"db": {"name": "db", "connector": "cloudant", "url": "https://...", "database": "composer-cards", "iamApiKey": "your-key-here"}}'

Windows Command Prompt

set COMPOSER_DATASOURCES={"db": {"name": "db", "connector": "cloudant", "url": "https://...", "database": "composer-cards", "iamApiKey": "your-key-here"}}

Docker Deployment

Include the variable when running the rest server container:

docker run -e COMPOSER_DATASOURCES='{"db": {...}}' hyperledger/composer-rest-server -c <your-admin-card> -n never -w true
Step 5: Verify the setup

Start your Composer Rest Server, then:

  1. Check your Cloudant database — you should see new documents of type Card when you import or create a card via the REST API.
  2. Test creating a card through the REST interface, then confirm it appears in the Cloudant database.

Quick Notes

  • Double-check that your IAM API Key has Writer access to the Cloudant database (you can set this in IBM Cloud’s IAM policies).
  • If you run into SSL issues (unlikely for IBM Cloud-hosted Cloudant), add "ssl": true to the db object in your JSON config.

内容的提问来源于stack exchange,提问作者MrL

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 11:39:13