hasCollection - 检查 Collections
hasCollection() 用于检查指定的 Collection 在数据库中是否存在。
信息
仅支持在使用 SeekdbClient 连接时,才能使用该接口。关于 SeekdbClient 的详细介绍,参见 SeekdbClient。
前提条件
-
您已经安装了 seekdb-js,有关安装 seekdb-js 的详细信息,参见 快速开始。
-
您已经安装了 seekdb 服务器模式,有关安装 seekdb 服务器模式的详细信息,参见 通过 yum install 部署 seekdb。
-
您已经连接到数据库。有关连接的详细操作参见 SeekdbClient。
请求参数
hasCollection(name: string)
| 参数 | 取值类型 | 是否必选 | 描述 | 取值示例 |
|---|---|---|---|---|
name | string | 必选 | 指定要检查的 Collection 的名称。 | my_collection |
请求示例
import { SeekdbClient } from "seekdb";
// 1. Connect
const client = new SeekdbClient({
host: "127.0.0.1",
port: 2881,
user: "root",
password: "",
database: "test",
});
const exists = await client.hasCollection('my_collection');
console.log(exists);
返回参数
| 参数 | 取值类型 | 是否必选 | 描述 | 取值示例 |
|---|---|---|---|---|
Promise<boolean> | 必选 | true 表示集合存在,false 表示不存在。 | true |
返回示例
true