Automatically update a collection/database when new blog post is added

The Wix Blog Posts collection is read-only, so I created another collection [Blog Post Audios] to store customized values that is used in code. How can I link this new collection to the Posts collection so that if a new blog post is published, a new entry/row appears in my new collection [Blog Post Audios]?

This forum post has a good solutions, but I don’t know how to code it:
https://www.wix.com/velo/forum/coding-with-velo/automatically-update-a-collection-database-when-new-product-is-added

I need a similar solution: a job that reads a database (e.g. Posts collection) and populates another database with any new addition (Blog Post Audios collection).

But, I’m new to coding and don’t know exactly how to go about coding that job. I’ve got the job file and everything set up, but don’t know how to write the .js file for this job. Any suggestions?

I’m guessing something with “query” and “update” functions… If I could have an example to start with it would help a lot.

Thank you!:grin:

@jacobg @russian-dima @marenfpodarm maybe you guys can help me out.

updated!

This is just an example-code -snipet i have written in one of my projects, which has a similar function.

let myinterval
let DATA = [];

$w.onReady(async function (){
    myInterval = setInterval(()=>{dataRefresh();}, 3000);
});


async function dataRefresh() {console.log("Interval-running...");
    DATA[0] = await getBasicData(DB[0]); console.log(DATA[0]);
    if(DATA[0].items) {$w('#btnLoad').disable();}
    else {$w('#btnLoad').enable(); }    
    
    if(DATA[0].dataInfo !== "No data found!") {                         
        $w(REPEATER[1]).expand(); $w(REPEATER[1]).show(); 
    }           
    else {$w(REPEATER[1]).hide(); $w(REPEATER[1]).collapse();
        REPEATER.forEach(element => {$w(element).data = [];});
        let msg = {}
        msg.type=               "Alert";
        msg.title=              "!!! Attention !!!";
        msg.message=            "No categories or data found, please check SHOWCASE-DATABASE!!!";
        msg.info=               "Please RELOAD the DATABASE!!!";
        msg.errorCode=          "00011/Admin-Control-Panel";
        msg.btnControlVisibility="show";
        msg.btnLabel=           "CLOSE";
        wixWindow.openLightbox("Alert-Box", msg)
        .then(async(res) => {console.log("Res-Lightbox-Data: ", res);});
    }   
    clearInterval(myInterval);
    setTimeout(()=>{},3000); 
    myInterval = setInterval(()=>{dataRefresh();}, 7500);
}

You start this interval-function from onReady().
It’s function is something like…

Start and look for DATABASE-DATA all time untill you find some DATA inside this database → STOP when found data.

You can write different interval-functions and create your own one.

Maybe a cron-job is still the better option, not sure.

It also opens a lightbox, but this is just additional customized function.

Cut of all not needed code-parts and try to inspect and understand how it works.