hasCollection - Check collections
hasCollection() is used to check whether a specified collection exists in the database.
info
This API can only be used when connected with SeekdbClient. For more information about SeekdbClient, see SeekdbClient.
Prerequisites
-
You have installed seekdb-js. For more information, see Quick start.
-
If you use seekdb in server mode, make sure seekdb server mode is installed. For more information, see Deploy seekdb with package managers.
-
You have connected to the database. For more information, see SeekdbClient.
Request parameters
hasCollection(name: string)
| Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|
name | string | Yes | The name of the collection to be checked. | my_collection |
Request example
import { SeekdbClient } from "seekdb";
// 1. Connect
// Embedded mode - Database management (seekdb Embedded)
// const client = new SeekdbClient({
// path: "./seekdb.db",
// database: "test",
// });
// Remote server mode - Database management (seekdb Server)
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);
Response parameters
| Parameter | Type | Required | Description | Example value |
|---|---|---|---|---|
Promise<boolean> | Yes | true indicates that the collection exists. false indicates that the collection does not exist. | true |
Response example
true