ravendb / ravendb-nodejs-client

RavenDB node.js client
MIT License
63 stars 32 forks source link

Deleting does not work in bulk #405

Closed Darkmift closed 8 months ago

Darkmift commented 9 months ago

Tried several variations of the docs https://www.npmjs.com/package/ravendb#crud-example

Nothing works on deletion

export async function deleteCollection(collectionName: string): Promise<void> {
    const session = store.openSession();
    try {
        const documents = (await session
            .query({ collection: collectionName })
            .all()) as RavenDocument[];
            // data is fetched properly here
        for (const document of documents) {
            await session.delete(document);
        }
        await session.saveChanges();
    } catch (error) {
        console.error('Error deleting documents:', error);
        throw error;
    } finally {
        session.dispose();
    }
}
ml054 commented 9 months ago

Can you share an exception with us?

For deleting entire collection I'd go with DeleteByQueryOperation.

Code examples: https://github.com/ravendb/ravendb-nodejs-client/blob/bed9ee9ca9982c03d40eae35f5e2fdbe6388ed2a/test/Documents/Operations/DeleteByQueryTest.ts#L13

Darkmift commented 8 months ago

Thank you for your reply. I hope to review your DB again in the future.

ml054 commented 8 months ago

I'm happy I could help. Can I assume we can close this ticket?

Darkmift commented 8 months ago

Yes please do.