Skip to content

Cloud Code - AddUnique to an Array in Database #805

Closed
@sanergulec

Description

@sanergulec

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) {

    }

  });

}); 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions