Yurii,
Thanks for the help. I wanted to post back here my working server code - in case someone else might find this helpful. Your hints plus the docs - spot on - and writing the code was easier and more efficient than doing it in my front end. I've of course changeid's and masterkeys to be safe.....
Thanks again.....
--------------------------------------Working server script to delete rows 'in bulk' that
-- match a where clause - the where clause comes into the script as a parameter - there are 2 parameters inbound - the userid and the whereclause --------
***********************************************************************************
var responseBody = {},
requestParams = {},
paramKeys = request.keys();
for (var key = 0; key < paramKeys.length; key++) {
requestParams[paramKeys[key]] = request.get(paramKeys[key]);
}
responseBody.requestBody = request.body();
responseBody.requestParams = requestParams;
responseBody.method = request.method; // responseBody.method now contains string "GET" or "POST".--- here I used GET.
// code to do the work. Login to the database with the master key,
// and then - delete the requested rows...
var dbId = "14bad3d2-e20f-xxxx-xxxx-xxxxxxxxxx"; // the api key from the control panel of your database
var smasterkey= 'xxxxxxx-xxxxx-xxxx-xxxxxxxxxxxxx' // the master key from the control panel of your database
var collectionName = "nameofcollectionwhereyouwanttodoabulkdelete"; // the name of the collection
// login....
var swhereclause = request.get("swhereclause"); //Store the where clause from the inbound paramter
var susername = request.get('susername') ; // username from the inbound parameter
console.log( "the where clause is:" + swhereclause + " the user name is:" + susername ); // log the parms to the console for debugging
var query = [] ;
var spassword = '' ;
try
{
result = {};
console.log('inside try loop');
var token = DatabaseUser.login(dbId , susername , null , smasterkey ).sessionToken; //Login the user and save its sessionToken to the variable
result.token = token; //Save it token to the result too
console.log('I am logged in');
// now logged in...
var params = {};
params.criteria = swhereclause ;
console.log('about to execute query');
queryResult = Collection.query(dbId, collectionName, params);
console.log('Rows returned:' + queryResult.length );
for(var i = 0; i < queryResult.length; i++){
console.log('executing delete object:' + queryResult.id );
Collection.deleteObject(dbId, collectionName, queryResult.id);
queryResult
};
console.log('there was success');
responseBody.success = queryResult.length + " items deleted";
responseBody.error = "";
}
catch (e)
{
console.log('there was an error: ' + e.message + ' Error ncode was:' + e.code );
responseBody.success = "";
responseBody.error = "message: " + e.message + "ncode: " + e.code;
}
console.log('outside try loop')
console.log(responseBody);
response.success(responseBody, "application/json");
// don't forget to logout of the db ... I know I did....
DatabaseUser.logout(dbId, token);
console.log('logged out of db & script complete');
// golf clap occurs here when you get the results in your service - and then you can query them from your UI...