Getting a list of all databases in the account
To list all the databases in an account, send a GET
request to https://$ACCOUNT.cloudant.com/_all_dbs
.
See the following example of using HTTP to list all databases:
GET /_all_dbs HTTP/1.1
See the following example to list all databases:
curl -H "Authorization: Bearer $API_BEARER_TOKEN" -X GET "$SERVICE_URL/_all_dbs"
import com.ibm.cloud.cloudant.v1.Cloudant;
import com.ibm.cloud.cloudant.v1.model.GetAllDbsOptions;
import java.util.List;
Cloudant service = Cloudant.newInstance();
List<String> response =
service.getAllDbs().execute().getResult();
System.out.println(response);
const { CloudantV1 } = require('@ibm-cloud/cloudant');
const service = CloudantV1.newInstance({});
service.getAllDbs().then(response => {
console.log(response.result);
});
from ibmcloudant.cloudant_v1 import CloudantV1
service = CloudantV1.new_instance()
response = service.get_all_dbs().get_result()
print(response)
getAllDbsOptions := service.NewGetAllDbsOptions()
result, response, err := service.GetAllDbs(getAllDbsOptions)
if err != nil {
panic(err)
}
b, _ := json.MarshalIndent(result, "", " ")
fmt.Println(string(b))
The previous Go example requires the following import block:
import (
"encoding/json"
"fmt"
"github.com/IBM/cloudant-go-sdk/cloudantv1"
)
All Go examples require the service
object to be initialized. For more information, see the API documentation's Authentication section for examples.
See the following example response that is a JSON array with all the database names:
[
"_users",
"contacts",
"docs",
"invoices",
"locations"
]