milvus-logo
LFAI
< Docs
  • Java
    • v1

createDatabase()

The MilvusClient interface. This method creates a database.

R<RpcStatus> createDatabase(CreateDatabaseParam requestParam);

CreateDatabaseParam

Use the CreateDatabaseParam.Builder to construct a CreateDatabaseParam object.

import io.milvus.param.collection.CreateDatabaseParam;
CreateDatabaseParam.Builder builder = CreateDatabaseParam.newBuilder()

Methods of CreateDatabaseParam.Builder:

Method

Description

Parameters

withDatabaseName(String databaseName)

Sets the database name. Database name cannot be empty or null.

databaseName: The database name.

withReplicaNumber(int replicaNumber)

Sets the replica number in database level, then if load collection doesn't have replica number, it will use this replica number.

replicaNumber: Replica number

withResourceGroups(List<String> resourceGroups)

Sets the resource groups in database level, then if load collection doesn't have resource groups, it will use this resource groups.

resourceGroups: Resource group names

build()

Construct a CreateDatabaseParam object.

N/A

The CreateDatabaseParam.Builder.build() can throw the following exceptions:

  • ParamException: error if the parameter is invalid.

Returns

This method catches all the exceptions and returns an R<RpcStatus> object.

  • If the API fails on the server side, it returns the error code and message from the server.

  • If the API fails by RPC exception, it returns R.Status.Unknown and the error message of the exception.

  • If the API succeeds, it returns R.Status.Success.

Example

import io.milvus.param.collection.CreateDatabaseParam;

CreateDatabaseParam param = CreateDatabaseParam.newBuilder()
        .withDatabaseName("mydb")
        .build();
R<RpcStatus> response = client.createDatabase(param)
if (response.getStatus() != R.Status.Success.getCode()) {
    System.out.println(response.getMessage());
}
Feedback

Was this page helpful?