I'm trying to delete entries from Azure CosmosDB.
Documetation says:
/**
* Delete item
* Pass the id and partition key value to delete the item
*/
const { resource: result } = await container.item(id, category).delete();
console.log(`Deleted item with id: ${id}`);
My function to delete and items is:
// takes in an entry id to detete and deletes it with the documentation
async function findItemsToDelete(idToDelete){
const category = config.partitionKey; // partitionKey is {kind: "Hash", paths: ["/requests"]} and I've also tried just "/requests"
// the four lines below are correct
const { endpoint, key, databaseId, containerId } = config;
const client = new CosmosClient({ endpoint, key });
const database = client.database(databaseId);
const container = database.container(containerId);
// query to return item with id (random code to make sure the item exists)- not important
const querySpec = {
query: `SELECT * FROM c WHERE c.id = "${idToDelete}"`
};
const { resources: items } = await container.items
.query(querySpec)
.fetchAll();
// below is the delete code from the documentation
const { resource: result } = await container.item(idToDelete, category).delete();
// random array holding the item that was just deleted- not important
return items;
}
When I try calling this, I get an error that says: Entity with the specified id does not exist in the system. Does anyone know how to properly implement this? I know the id is correct but I believe I may be doing something wrong with the partitionKey/Category part.
I saw in this post: Cannot delete item from CosmosDB that i may need the partition key value, but I dont know what that is or how to get it. Please let me know if you know what's going on!