parse.com - Javascript - Delete duplicates in class -



parse.com - Javascript - Delete duplicates in class -

i have class in parse called testitem here snap shot of class

so trying write code function remove this. there not more duplicates. have tried

parse.cloud.job("removeduplicateitems", function(request, response) { function checkduplicate(school) { var testitem = parse.object.extend("testitem"); var testitemsquery = new parse.query(testitem); testitemsquery.equalto('school', schoolarray[i]); testitemsquery.each(function(testitem) { var item = testitem.get('item'); var school = testitem.get('school'); var dininghallnum = testitem.get('dininghallnumber'); var testitemsquerycheck = new parse.query(testitem); testitemsquerycheck.equalto ('item', item); testitemsquerycheck.equalto ('school', school); testitemsquerycheck.equalto ('dininghallnumber', dininghallnum); //then delete item } var schoolarray = ['union college (ny)', 'university of albany', 'rensselaer polytechnic institute']; (var = 0; < schoolarray.length; i++) { checkduplicate(schoolarray[i]); } }

but doesn't work because come true need way see if sec time item has come up. how go doing this?

thanks help in advance!!!

edit

if have data

deletes 1 of cheese items , item?

this should work

parse.cloud.job("removeduplicateitems", function(request, status) { parse.cloud.usemasterkey(); var _ = require("underscore"); var hashtable = {}; function hashkeyfortestitem(testitem) { var fields = ["item", "meal", "schoolmenu", "dininghallnumber", "school"]; var hashkey = ""; _.each(fields, function (field) { hashkey += testitem.get(field) + "/" ; }); homecoming hashkey; } var testitemsquery = new parse.query("testitem"); testitemsquery.each(function (testitem) { var key = hashkeyfortestitem(testitem); if (key in hashtable) { // item seen before, destroy homecoming testitem.destroy(); } else { // not in hashtable, maintain hashtable[key] = 1; } }).then(function() { status.success("migration completed successfully."); }, function(error) { status.error("uh oh, went wrong."); }); });

javascript parse.com cloud

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

Local Service User Logged into Windows -