I added a new empty page and wrote this simple code below, to insert a log into a collection, here is the result:
- only one ‘$w.onReady called’ printed
- only one ‘dump_log called’ printed
- TWO ITEMS with same value except _id inserted into the collection
I tried different collection, I deleted async/await, I moved the code to another page wether it’s new or old, all the same result!!!
Really can’t figure why this happens , could anyone help me?
import wixData from 'wix-data';
async function dump_log(msg) {
console.log('dump_log called');
let mmm = {
title: 'test-title',
args: 'no args',
logType: 'log',
logMessage: 'why???'
};
await wixData.insert('backendlog', mmm)
.then((result) => {})
.catch((error) => {
console.error(error.message);
});
}
$w.onReady(async function () {
console.log('$w.onReady called');
await dump_log('dump msg');
});