Skip to main content

Create Data Source

Create a new database connection configuration in NineData.

Request URL: /openapi/v1/datasource/create

Request Method: POST

Request Parameters

ParameterTypeRequiredDescriptionExample
datasourceTypeStringYesData source type. Supported values: MYSQL, MARIADB, POSTGRESQL, SQLSERVER, DAMENG, KINGBASE, KINGBASE_ORACLE, MILVUS, MONGODB. Values are case-insensitive. Uppercase is recommended.MONGODB
nameStringYesSpecify the name of the data source.Production Environment MongoDB
usernameStringNoAccount for accessing the data source.root
passwordStringNoPassword for accessing the data source.Root
hostStringYesConnection 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
portIntegerNoPort 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
envIdStringNoBind this data source to a specific environment. You can call the List Environments API to get envId.env-product
regionIdStringNoSpecify 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.
networkTypeStringNoSpecify the connection method of the data source. Currently, only public network access is supported, with the value being Public.Public
extraConfigObjectNoData-source-specific configuration. Put type-specific parameters in this object.{"authDB":"admin"}
sslConfigObjectNoSSL configuration. Currently supported only for MySQL, SQLServer, and PostgreSQL. Do not pass this parameter for MongoDB.{"securityConfig":"PREFERRED"}

MongoDB-Specific extraConfig Parameters

ParameterTypeRequiredDefaultDescriptionExample
mongoDBDeploymentTypeStringNostandaloneMongoDB deployment type. Values: standalone, replicaSet, shardedCluster.replicaSet
authDBStringYes-Authentication database.admin
readPreferenceStringNo-Read preference. Values: primary, primaryPreferred, secondary, secondaryPreferred, nearest.secondaryPreferred
replicaSetStringNo-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.

ParameterTypeRequiredApplicable Data SourcesDescriptionExample
securityConfigStringNoMySQL, PostgreSQLSSL security mode. MySQL values: REQUIRED, PREFERRED; PostgreSQL values: Prefer, Require, Verify-CA, Verify-Full.PREFERRED
sslCipherStringNoMySQLSSL cipher suite.TLS_AES_256_GCM_SHA384
sslCAStringNoMySQL, SQLServer, PostgreSQLCA certificate content.-----BEGIN CERTIFICATE-----
sslCAFileNameStringNoMySQL, SQLServer, PostgreSQLCA certificate file name.ca.pem
sslClientCertStringNoMySQL, PostgreSQLClient certificate content.-----BEGIN CERTIFICATE-----
sslClientCertFileNameStringNoMySQL, PostgreSQLClient certificate file name.client-cert.pem
sslClientKeyStringNoMySQL, PostgreSQLClient private key content.-----BEGIN PRIVATE KEY-----
sslClientKeyFileNameStringNoMySQL, PostgreSQLClient private key file name.client-key.pem
sslIndentifyBooleanNoMySQLWhether to verify the server identity. Use the field name sslIndentify as required by the API.false
hostNameInCertificateStringNoSQLServerHost name in the server certificate.db.example.com
trustServerCertificateBooleanNoSQLServerWhether 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

ParameterTypeDescriptionExample
successBoolWhether the API call was successful. Return values: true, false.true
requestIdStringRequest ID.Mi6y0FCN-BHEEaHAnCFFp9DFdAAk0OUZ
dataArrayDetails 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"
}
}