Skip to main content

Drop Document

To drop an document you need to retrieve a specific document from a collection first then delete it. This is particularly useful for managing or cleaning up data.

Definition

Each instance of Document has a method called drop(), which can be used to delete the document from the database.

await document.drop();

Parameters

  • None

Returns

The operation returns a Promise that resolves to the deletion acknowledgment in boolean.

Example

This example shows how to connect to a zkDatabase, authenticate, retrieve a document by its name, and delete it using the drop method.

import { ZkDatabase } from 'zkdb';

const zkdb = await ZkDatabase.connect({
userName: "chiro-user",
privateKey: "EKFTciRxyxshZjimay9sktsn7v5PvmC5zPq7q4JnitHUytxUVnFP",
environment: "node",
// This URL is for test environment
url: "https://api.zkdatabase.org/graphql",
});

await zkdb.auth.signIn();

const collection = await zkdb.db('zkdb_test').collection('test_collection');

const doc = await collection.findOne({ name: 'Test Shirt' });

if (doc) {
await doc.drop();
}


await zkdb.auth.signOut();