Urgent! Problem with database - Network error

Hi,
Yesterday i changed some small code wich added some data to the database.
The problem is that i can’t access my database anymore except when i filter it so i don’t see the data with the error in it.

anyone can take a look at it?

Editor link

The problem is in the OffertesTest database.

What did i do:
on the pages “Voorzetrolluik”,“Rolluikblad”,“Inbouwrolluik”
I had a function named “getRalAndPoedercode()”
I made a new function named “getRalKleur()”
In the end it does the same as the getRalAndPoedercode() but in a smaller code.
(This code does work in “Voorzetrolluik”)
It gets some data from the database and adds the data to some variable’s i have on the page.
i called this function " getRalAndPoedercode()" in 2 onChange events.
1- when my $w(“#rbKleurOnderlat”).value has changed.
2- when my $w(“#ddPoedercode”).value has changed.

This data is later added to the databse “OffertesTest”

I had a problem with getRalAndPoedercode() that it didn’t always retrieved the data before the data was added to the database, so i made a new function to make it work,
In “Voorzetrolluik” i tested it and it did work.
but when doing the same thing in “Rolluikblad” and “Inbouwrolluik” it crashes my database.

Kind regards,
Kristof

An observation… On the Voorzetrolluik page, you have a couple of flagged errors. These will need to be fixed before you can ensure that things will work properly. Here’s one error for example:

In your getRalKleur() function, you are improperly handling the Promise returned from the database query:

The purpose of the .then() function is to handle the Promise when it is fulfilled. The purpose of await is block execution from continuing until the Promise is fulfilled and the result is returned. It is incorrect to use both await and .then() together. I really don’t know what would happen in this case. The best I can say is that the results would be unpredictable.

I’m not the best with working with promises, there could be a few more errors in the code about that.
So when you work with a .then() you don’t have to use await?
I will take a look at it.

about the "if (Size === “” || …
It just to make an error in the case it would return a empty string, null or undefined
just to make sure the code will end before starting to add to the database.

About the problem in the database,
If you open the database “OffertesTest” - LIVE VERSION
Filter on todays date (28/01/2021)
&
Filter on SortNr equal to 60.
You will see that the database gives an network error,
If you change it to 10,20 or not equal to 60 it will show you the data.
So i don’t know what happend or what is added so that it is broken.

Kind regards,
Kristof.

@volkaertskristof The main difference between await and using .then() to handle promises is that await fn() suspends execution of the current code, while promise.then(fn) continues execution of the current code, after adding the fn() call to the callback chain.
For more information on Promises:

"about the "if (Size === “” || … "
Size is a number and not a string. So, comparing size to a blank string is a problem.

I opened your site in the Editor and am unable to open any of your database collections. Not sure if that’s an issue on my side or if it’s connected with your database problem. I’m going to refer this to QA for evaluation.

@yisrael-wix
I will try to remember it,
I tried some stuff since sometimes it skipped my code while it should have excecuted first so now there are some await with .then() promises together :sweat_smile:

I will take a look at the links you provided,
I hope i understand evrything correcty since my english isn’t top notch and understanding some words might be a bit harder.

I opened your site in the Editor and am unable to open any of your database collections. Not sure if that's an issue on my side or if it's connected with your database problem. I'm going to refer this to QA for evaluation.

Well i only have the problem from today and yesterday, if i filter on created day 26/01/2021 in the “OffertesTest” database it works fine, if i filter and the “broken” cell is not filtered away it gives the network error.

Kind regards,
Kristof.

@volkaertskristof Your English is fine. On the other hand, the last time I used German was in Junior High - back when dinosaurs roamed the planet.

I hope that QA will be able to understand what happened to your database. Worst case, you can revert to an older version in the dashboard’s site history. Maybe an older version will work.

@yisrael-wix
My english is fine but understanding words for coding is sometimes hard to understand :slight_smile:

Let me know if QA answerd :slight_smile:

Kind regards,
Kristof.

I did went to an older version, seems to work again now.
Didn’t knew i could do that :sweat_smile:

1 Like

@yisrael-wix
1 question,

If i use:
function someFunction(){
    return wixData.query("something")
    .find()
    .then(res =>{
        return res
    })
       .catch(err=>{
       console.log(err)
    })
}

Do i have to await till the function is done?

async function doSomething(){
let someVariable = await someFunction()
//do something with 'someVariable'
}

or do i not have to use the await here?

Kind regards,
Kristof.

@volkaertskristof You got it right. Either await or .then() for the calling code. See Returning in a .then( ) for an excellent explanation and sample code.

@yisrael-wix
Just to be sure… :sweat_smile:
My Function:

function someFunction(){
    return wixData.query("something")
    .find()
    .then(res =>{
        return res
    })
       .catch(err=>{
       console.log(err)
    })
}

The way i can use it.

like this:

async function doSomething(){
let someVariable = await someFunction()
//do something with 'someVariable'
}

OR like this?:

let someVariable;
function doSomething(){
    someFunction()
    .then(res =>{
        someVariable = res.items
    }
    // do something with someVariable
}

Sorry for taking your time, This isn’t urgent so only answer when you have time :sweat_smile:

Kind regards,
Kristof.

@volkaertskristof Well, why not just try it out. Without actually trying it out myself…

You should be able to use either one. As we discussed before, you can’t use both await and then() .