The only delete operation I get deletes one at a time: https://www.windowsazure.com/en-us/develop/nodejs/how-to-guides/table-services/#delete-entity
What I want is equivalent to the SQL statement
DELETE FROM MyTable WHERE PartitionKey = 'something'
Also on that page is a way to send a batch (although I could not get this to work with delete, anyone know why?). However, I'd first have to do a select to get the list of entities I want to delete in order to get their RowKeys. I was wondering whether it's possible to do it in only one request to Azure.
Thanks in advance.
UPDATE: Here's the code I tried and it doesn't work. I have confirmed that all arguments are correct when the function is called.
// subAccts all have PartitionKey = pKey
function deleteAccount(pKey, rKey, subAccts, callback) {
var tasks = subAccts; // rename for readability
tasks.push({ PartitionKey: pKey, RowKey: rKey });
tableService.beginBatch();
async.forEach(tasks, function(task, callback) {
tableService.deleteEntity(myTable, task, function(error) {
if (!error) {
callback(null);
}
else {
console.log(error);
callback(error);
}
});
}, function(error) {
if (error) {
console.log(error);
callback(error);
return;
}
tableService.commitBatch(callback);
});
}
If you don't know the list of entities you want to delete in advance, you'll have to query first to find them.
You might consider restructuring your table, though. If, instead of just putting these entities in the same partition, you could put them all in the same table (by themselves), you could delete the table. This is commonly used for deleting old logs... create tables like log_january, log_february, and then you can just delete an entire month at a time with a single command.
EDIT
There appears to be a bug in the library. Try this edit as a workaround:
BatchServiceClient.prototype.addOperation = function (webResource, outputData) {
if (azureutil.objectIsNull(outputData)) {
outputData = '';
}
if (webResource.httpVerb !== 'GET') {
webResource.headers[HeaderConstants.CONTENT_ID] = this.operations.length + 1;
if (webResource.httpVerb !== 'DELETE') {
webResource.headers[HeaderConstants.CONTENT_TYPE] = 'application/atom+xml;type=entry';
} else {
delete webResource.headers[HeaderConstants.CONTENT_TYPE];
}
...
I've created a pull request to fix this in the dev branch: https://github.com/WindowsAzure/azure-sdk-for-node/pull/300.
Until this is fixed, you can always clone my fork (https://github.com/smarx/azure-sdk-for-node), checkout the dev
branch, and npm install
that, rather than hand-editing the code.