Skip to main content

Drop Document

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

Definition​

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

const dropResult = await document.drop();
if (dropResult.isOk()) {
console.log('Deleted successfully');
}

Parameters​

  • None

Returns​

The operation returns a Result that can be checked with .isOk() / .isErr().

Example​

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

import { ZkDatabase } from 'zkdb';

const zkdb = new ZkDatabase({
apiKey: 'zkdb_536aac02a1b7.c001b6b8f...da3aa4185d8d2ad07f0ae94aT',
// This URL is for test environment
url: "https://serverless.zkdatabase.org/graphql",
});
const collection = await zkdb.db('zkdb_test').collection('test_collection');

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

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