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

Triggers after creating an object in cloud code

Open anthonylai opened this issue 10 years ago • 9 comments

Objects created through cloud code no longer triggers beforeSave and afterSave handlers for that object.

anthonylai avatar Feb 01 '16 00:02 anthonylai

They should, since cloud code uses the client methods and calls back in to the server... Did you make sure to change the Parse.serverURL to point to your API server in cloud code? (We do need to document this better.)

gfosco avatar Feb 01 '16 05:02 gfosco

This is the settings I have. Is this what you refer as the Parse.serverURL?

var api = new ParseServer({ databaseURI: 'mongodb://localhost:27017/db', cloud: '/Users/alai/dev/cloud/main.js', // Provide an absolute path appId: 'xxxxxxxx', masterKey: 'yyyyyyyy', facebookAppIds: [ 'zzzzzzzzzzzz' ]
// fileKey: 'optionalFileKey' });

// Serve the Parse API on the /parse URL prefix app.use('/parse', api);

For me, the beforeSave/afterSave triggers get called from iOS sdk when an object is modified, but the triggers are not called in my cloud code (main.js) when an object is modified there.

anthonylai avatar Feb 01 '16 16:02 anthonylai

I think this is the reason: https://github.com/ParsePlatform/parse-server/issues/131

r4zzz4k avatar Feb 01 '16 16:02 r4zzz4k

Actually, it looks like the objects I try to create in cloud code through object.save() does not get created in MongoDB. This maybe the root cause of why the triggers are not executed.

For example: var createLog = function(object) { Parse.Cloud.useMasterKey(); var log = new Parse.Object('Log'); var acl = new Parse.ACL(); log.setACL(acl); log.set('objectClassName', object.className); log.set('action', object.get('lastAction')); log.save(); console.log('Log created for ' + className); };

The console.log('Log created for ' + className); shows up in the console, but the record is not created in MongoDB.

anthonylai avatar Feb 01 '16 17:02 anthonylai

Your Cloud Code is probably trying to save an object against parse.com and either saves it successfully or silently fails depending on whether app with the same appId exists there.

r4zzz4k avatar Feb 01 '16 17:02 r4zzz4k

@r4zzz4k how do I set it to my own localhost than parse.com?

anthonylai avatar Feb 01 '16 17:02 anthonylai

@r4zzz4k Yes, you are correct, the object get saved in Parse.com! How to modify this behavior?

anthonylai avatar Feb 01 '16 17:02 anthonylai

Here is how I've managed to overcome this issue on my server: https://github.com/ParsePlatform/parse-server/pull/132

r4zzz4k avatar Feb 01 '16 17:02 r4zzz4k

Closing this issue as duplicate as the root cause is issue #132

anthonylai avatar Feb 01 '16 20:02 anthonylai