跳到主要内容
版本:v2.6.x

hasCollection()

This operation checks whether a specific collection exists.

Java
public Boolean hasCollection(HasCollectionReq request)

Request Syntax

Java
hasCollection(HasCollectionReq.builder()
.databaseName(String databaseName)
.collectionName(String collectionName)
.build()
)

BUILDER METHODS:

  • databaseName(String databaseName)

    The name of the database to which the target collection belongs.

  • collectionName(String collectionName)

    The name of a collection.

RETURN TYPE:

bool

RETURNS:

A boolean value indicating whether the specified collection exists.

EXCEPTIONS:

  • MilvusClientExceptions

    This exception will be raised when any error occurs during this operation.

Example

Java
import io.milvus.v2.client.ConnectConfig;
import io.milvus.v2.client.MilvusClientV2;
import io.milvus.v2.service.collection.request.HasCollectionReq;

// 1. Set up a client
ConnectConfig connectConfig = ConnectConfig.builder()
.uri("http://localhost:19530")
.token("root:Milvus")
.build();

MilvusClientV2 client = new MilvusClientV2(connectConfig);

// 2. Check whether the collection exists
HasCollectionReq hasCollectionReq = HasCollectionReq.builder()
.collectionName("test")
.build();
Boolean resp = client.hasCollection(hasCollectionReq);