parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Cloud Code - AddUnique to an Array in Database

Open sanergulec opened this issue 10 years ago • 1 comments

Hello,

I try to add an id to an array stored in my database. Is the "addUnique" property that is stated in the parse js guideline not working in the cloud code? How can we add and remove an item from an array? My code that is not working currently is as below:

Parse.Cloud.afterSave('myArchive', function(req) {

  var followCount = Parse.Object.extend('followCount');
  var query = new Parse.Query(followCount);
  query.equalTo('userid', req.user.id);
  query.find({

    success: function(result) {

        if ( result.length > 0 ) {


            result[0].addUnique('archiveArray', 'tatattataa');  //the archiveArray is an array in the followCount database
            result.save(null, { useMasterKey: true });

        }

        else {

        }

    },

    error: function(error) {

    }

  });

}); 

sanergulec avatar Mar 03 '16 11:03 sanergulec

I updated as below and it worked:

 result[0].addUnique('archiveArray', 'tatattataa');  //the archiveArray is an array in the followCount database
 result[0].save(null, { useMasterKey: true });

sanergulec avatar Mar 03 '16 12:03 sanergulec