Create Data Source
Create a new database connection configuration in NineData.
Request URL: /openapi/v1/datasource/create
Request Method: POST
Request Parameters
| Parameter | Type | Required | Description | Example |
|---|---|---|---|---|
| datasourceType | String | Yes | Data source type. Supported values: MYSQL, MARIADB, POSTGRESQL, SQLSERVER, DAMENG, KINGBASE, KINGBASE_ORACLE, MILVUS, MONGODB. Values are case-insensitive. Uppercase is recommended. | MONGODB |
| name | String | Yes | Specify the name of the data source. | Production Environment MongoDB |
| username | String | No | Account for accessing the data source. | root |
| password | String | No | Password for accessing the data source. | Root |
| host | String | Yes | Connection address of the data source. For MongoDB standalone mode, pass an IP address or domain name. For a replica set or sharded cluster, pass a comma-separated string in the host1:port1,host2:port2 format. | 192.168.1.1 |
| port | Integer | No | Port number of the data source. Required for MongoDB standalone mode. Do not pass this parameter for a MongoDB replica set or sharded cluster because port information is included in host. | 27017 |
| envId | String | No | Bind this data source to a specific environment. You can call the List Environments API to get envId. | env-product |
| regionId | String | No | Specify the region where the data source belongs. You can call the List Regions API to get regionId. | Please use the obtained regionId as the reference. |
| networkType | String | No | Specify the connection method of the data source. Currently, only public network access is supported, with the value being Public. | Public |
| extraConfig | Object | No | Data-source-specific configuration. Put type-specific parameters in this object. | {"authDB":"admin"} |
| sslConfig | Object | No | SSL configuration. Currently supported only for MySQL, SQLServer, and PostgreSQL. Do not pass this parameter for MongoDB. | {"securityConfig":"PREFERRED"} |
MongoDB-Specific extraConfig Parameters
| Parameter | Type | Required | Default | Description | Example |
|---|---|---|---|---|---|
| mongoDBDeploymentType | String | No | standalone | MongoDB deployment type. Values: standalone, replicaSet, shardedCluster. | replicaSet |
| authDB | String | Yes | - | Authentication database. | admin |
| readPreference | String | No | - | Read preference. Values: primary, primaryPreferred, secondary, secondaryPreferred, nearest. | secondaryPreferred |
| replicaSet | String | No | - | Replica set name. You can pass this parameter for MongoDB replica set mode. | rs0 |
SSL Configuration Parameters
Only MySQL, SQLServer, and PostgreSQL data sources support sslConfig. Supported fields vary by data source type.
| Parameter | Type | Required | Applicable Data Sources | Description | Example |
|---|---|---|---|---|---|
| securityConfig | String | No | MySQL, PostgreSQL | SSL security mode. MySQL values: REQUIRED, PREFERRED; PostgreSQL values: Prefer, Require, Verify-CA, Verify-Full. | PREFERRED |
| sslCipher | String | No | MySQL | SSL cipher suite. | TLS_AES_256_GCM_SHA384 |
| sslCA | String | No | MySQL, SQLServer, PostgreSQL | CA certificate content. | -----BEGIN CERTIFICATE----- |
| sslCAFileName | String | No | MySQL, SQLServer, PostgreSQL | CA certificate file name. | ca.pem |
| sslClientCert | String | No | MySQL, PostgreSQL | Client certificate content. | -----BEGIN CERTIFICATE----- |
| sslClientCertFileName | String | No | MySQL, PostgreSQL | Client certificate file name. | client-cert.pem |
| sslClientKey | String | No | MySQL, PostgreSQL | Client private key content. | -----BEGIN PRIVATE KEY----- |
| sslClientKeyFileName | String | No | MySQL, PostgreSQL | Client private key file name. | client-key.pem |
| sslIndentify | Boolean | No | MySQL | Whether to verify the server identity. Use the field name sslIndentify as required by the API. | false |
| hostNameInCertificate | String | No | SQLServer | Host name in the server certificate. | db.example.com |
| trustServerCertificate | Boolean | No | SQLServer | Whether to trust the server certificate. | false |
Request Example
MongoDB standalone:
{
"name": "Production Environment MongoDB",
"username": "root",
"password": "Root",
"host": "192.168.1.10",
"port": 27017,
"datasourceType": "MongoDB",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"extraConfig": {
"mongoDBDeploymentType": "standalone",
"authDB": "admin"
}
}
MySQL SSL:
{
"name": "Production Environment MySQL",
"username": "root",
"password": "Root",
"host": "192.168.1.10",
"port": 3306,
"datasourceType": "MYSQL",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"sslConfig": {
"securityConfig": "PREFERRED",
"sslIndentify": false
}
}
MongoDB replica set:
{
"name": "Production Environment MongoDB Replica Set",
"username": "root",
"password": "Root",
"host": "192.168.1.10:27017,192.168.1.11:27017",
"datasourceType": "MongoDB",
"regionId": "aliyun-cn-hangzhou",
"envId": "env-product",
"networkType": "Public",
"extraConfig": {
"mongoDBDeploymentType": "replicaSet",
"authDB": "admin",
"readPreference": "secondaryPreferred",
"replicaSet": "rs0"
}
}
Return Parameters
| Parameter | Type | Description | Example |
|---|---|---|---|
| success | Bool | Whether the API call was successful. Return values: true, false. | true |
| requestId | String | Request ID. | Mi6y0FCN-BHEEaHAnCFFp9DFdAAk0OUZ |
| data | Array | Details of the created data source, including data source ID (datasourceId) information. | { "datasourceId": "ds-d92r4i7z1a90" } |
Successful Invocation Example
{
"success": true,
"requestId": "Uf0f0KQB-BHEEjCWnCGHo9FSdCBi1GPC",
"data": {
"datasourceId": "ds-d92r4i7z1a90"
}
}