It looks like the problem is with the insert into the Posts_attributes collection. You need to await the call so that the insert completes before the query and updates are called. Currently, the code isn’t waiting for the insert to resolve so there isn’t a record in the Post_attributes collection to find or update.
Try changing:
wixData.insert(“Posts_attributes”, toInsert)
.then( (results) => {
let item = results; //see item below
} );
To:
let item = await wixData.insert(“Posts_attributes”, toInsert);