Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Deleting Multiple DB Entries Using "Where"

Hi Maryna,

It really seems like that should work, but for some reason it doesn't seem to be. I even did a test delete for a fixed record number which worked. Any ideas why it doesn't want to loop through the result object to get the list of _id values (see code below)? Is there a way that I can view what values are being assigned? I'm used to outputting them with a print command, but that doesn't seem to work here.

Can you explain a bit more how to implement console.log? Although I've come a far way with Appery I'm still pretty clueless on many of the basics.

Thanks Maryna!

PS ?How do I do the block greyed out text like yours above? code /code looks unseemly.

code
db_id = '52a4...';

collectionName = 'contacts';

//record_id = '52ec...';

owner_id = '52df...';

var user_id = request.get("user_id"); //Store the user_id

try {
result = {};

var params = {}; //Define parameters object
params.criteria = { //Query criteria:
'r_owner': owner_id
};

result.query = Collection.query(db_id, collectionName, params); //Make the query and save it to the result object

response.success(result);

//Loop through result
//get _id and set as record_id for each row in result.
//Perform delete record based on record_id

var i, len, record_id;

for(i = 0, len = result&#46;length; i < len; i++) {
record_id = result['_id'];

Code: Select all

 Collection&#46;deleteObject(db_id, collectionName, record_id); 

}

&#47;&#47;This TESTdeletion did work so I know it's functional
&#47;&#47;record_id = '52dfdb&#46;&#46;';
&#47;&#47;Collection&#46;deleteObject(db_id, collectionName, record_id);

} catch (e) {
response&#46;success("message: " + e&#46;message + "ncode: " + e&#46;code);
}
/code

Maryna Brodina
Posts: 0
Joined: Thu Apr 05, 2012 7:27 am

Deleting Multiple DB Entries Using "Where"

You assign result to result.query. preresult&#46;query = Collection&#46;query(db_id, collectionName, params); /preSo in loop you need to go through result.query, not result prevar i, len, record_id;
for(i = 0, len = result&#46;query&#46;length; i < len; i++) {
record_id = result&#46;query['_id'];
Collection&#46;deleteObject(db_id, collectionName, record_id);
}/pre

Christopher Herold
Posts: 0
Joined: Fri Jun 28, 2013 8:27 pm

Deleting Multiple DB Entries Using "Where"

Thanks again Maryna! Works perfectly.

Return to “Issues”