I'd like to have 2 collections that one mirrors the other. i.e. if I insert a new record or update an existing one in collection1, it'll immediately update collection2 accordingly (but not vise versa. The updates always take place on collection1 first).
So to do that I've created an afterUpdate and afterInsert hooks, which work fine, but the problem is that these hooks do not trigger on collection sync (from sandbox to live).
any advice how to achieve my goal?
Thanks,
I've the same issue, But I think it's preferable to not trigger the hook on syncing other you risk to duplicate your insert. The way I solved that is by having a dashboard page call "syncer" with a button. on click the syncer erase collection2 and duplicate all items from collection1 into 2. That will fork fine if you have less than 13000 items. Scripts timeout after that.
Other solution: Since hooks are active in sandboxe why not import collection B as well? a bit manual but no code required
Take a look at Reference Fields.
When you create reference fields, you create a pointer to a different collection, creating a connection between the collections in the actual structure of the primary collection.
This connection gives you access to all the information in all the referenced collections from within the primary collection: https://support.wix.com/en/article/about-connecting-multiple-database-collections
Maybe the update() function can also be helpful for what you are trying to achieve: https://www.wix.com/corvid/reference/wix-data.html#update