Skip to content
MilvusNode SDK
Sections

Create and Use Databases

Markdown

Copy for agent

Milvus supports multiple databases, allowing you to organize collections into logical groups. This guide covers all database operations.

Create a new database:

await client.createDatabase({
db_name: 'my_database',
});

Create a database with properties:

await client.createDatabase({
db_name: 'my_database',
properties: {
owner: 'analytics-team',
environment: 'production',
},
});

List all databases:

const result = await client.listDatabases();
console.log('Databases:', result.db_names);
// Output: ['default', 'my_database']

Get detailed information about a database:

const result = await client.describeDatabase({
db_name: 'my_database',
});
console.log('Database info:', result);

Modify database properties:

await client.alterDatabaseProperties({
db_name: 'my_database',
properties: {
owner: 'search-team',
environment: 'staging',
},
});

Remove specific properties from a database:

await client.dropDatabaseProperties({
db_name: 'my_database',
properties: ['environment'],
});

Delete a database (all collections in the database will be deleted):

await client.dropDatabase({
db_name: 'my_database',
});

When creating a client, specify the database:

const client = new MilvusClient({
address: 'localhost:19530',
database: 'my_database', // Set default database
});

Create separate clients for different databases:

await client.createDatabase({ db_name: 'database1' });
await client.createDatabase({ db_name: 'database2' });
const db1Client = new MilvusClient({
address: 'localhost:19530',
database: 'database1',
});
const db2Client = new MilvusClient({
address: 'localhost:19530',
database: 'database2',
});
console.log('database1:', (await db1Client.listCollections()).data);
console.log('database2:', (await db2Client.listCollections()).data);
await db1Client.closeConnection();
await db2Client.closeConnection();

Each database is isolated:

  • Collections in different databases are completely separate
  • Operations on one database don’t affect others
  • Users and roles can have different permissions per database
  1. Use databases for logical separation: Organize collections by application, environment, or team
  2. Default database: The default database is created automatically
  3. Database naming: Use descriptive names that reflect the purpose
  4. Permissions: Configure user permissions at the database level for security