[SOLVED] How sync_historical event work with beforeSave?

Hello.
I try to sync_historical event, and beforeSave I want to add new fields with my custom value. It work when event trigger but not work on the first time history sync. Please help.

Hi,
I think that you will have to make a separate job that processes historical events. That is because beforeSave trigger will not be applied to historical events from what I know.

2 Likes

Yes, you’r right. I have used a job and it work now. Thank you.

@cryptokid @locpx
I’m running into the same issue.
Can you give me some pointers on how do you create a separate job that will process the historical events the same way beforeSave/afterSave do?

you need a flag in a new column to know if the data was processed or not, and when you run the job (or a simple cloud function) you iterate over the entries that are found in the database table and if that flag is not set then you process that entry

Aha yes of course I could have thought about that :slight_smile:

Would it otherwise be possible by creating a Parse.Cloud.beforeSave trigger on the parse server itself instead of Moralis? Or would that effectively be the same as the Moralis.Cloud.beforeSave and thus not work?

I think that it would be the same thing as Moralis.Cloud.beforeSave

The historical data is saved differently to save it faster and that is why beforeSave is not triggered. Someone could sync millions of records with historical sync

Alright, that’s too bad but thanks for the info!