Using insert function for collection

Hi,

I’m trying to use the insert code to commit content to a database collection that I have created.

When I try running the code, I get this error in the developer console - WDE0025: The myCollection collection does not exist. You cannot work with a collection using the Data API before it is created in the Editor

I have tried multiple iterations of the collection name. Any help is greatly appreciated!

export function submit_click(event) {
 let A1 = $w('#DD8').value;
 let A2 = $w('#DD2').value;
 let A3 = $w('#DD1').value;
 let A4 = $w('#R1').value;
 let A5 = $w('#R2').value;
 let A6 = $w('#R3').value;
 let A7 = $w('#R4').value;
 let A8 = $w('#R5').value;
 let A9 = $w('#R6').value;
 let A10 = $w('#R7').value;
 let A11 = $w('#R8').value;
 let A12 = $w('#R9').value;
 let A13 = $w('#R10').value;

let toInsert = {

"a1": A1
"a2": A2,
"a3": A3,
"a4": A4,
"a5": A5,
"a6": A6,
"a7": A7,
"a8": A8,
"a9": A9,
"a10": A10,
"a11": A11,
"a12": A12,
"a13": A13
}

wixData.insert("myCollection", toInsert)

.then( (results) => {
 let item = results; //see item below
  } )
  .catch( (err) => {
 let errorMsg = err;
  } )

//if($w('#email').valid)
//$w('#viewresults').show(); 

Hello AR,

of course this will not work ^^

You have first to RENAME the variable —> “myCollection”
How is called your Database-Collection?

export function submit_click(event) {
 let A1 = $w('#DD8').value;
 let A2 = $w('#DD2').value;
 let A3 = $w('#DD1').value;
 let A4 = $w('#R1').value;
 let A5 = $w('#R2').value;
 let A6 = $w('#R3').value;
 let A7 = $w('#R4').value;
 let A8 = $w('#R5').value;
 let A9 = $w('#R6').value;
 let A10 = $w('#R7').value;
 let A11 = $w('#R8').value;
 let A12 = $w('#R9').value;
 let A13 = $w('#R10').value;

 let toInsert = {
 "a1": A1,
 "a2": A2,
 "a3": A3,
 "a4": A4,
 "a5": A5,
 "a6": A6,
 "a7": A7,
 "a8": A8,
 "a9": A9,
 "a10": A10,
 "a11": A11,
 "a12": A12,
 "a13": A13
    }

    wixData.insert("myCollection", toInsert) //<<<------- here is the important line (change the name of the variable to your own DATABASE-NAME)

    .then( (results) => {
 let item = results;
    } )
    .catch( (err) => {
 let errorMsg = err;
    })
}

Hi Russian-dima,

I’ve tried renaming it to the actual name (see below).

I’ve tried QuizData and dataset6. Neither of these work :frowning:

NOT —> DATASET ! :rofl:
You have to put in the name of your DATABASE! (Collection).

You are mixing DATASET with DATABASE!

@russian-dima Do i put in “QuizData”?

@ar1

Hello again.

Do the following…

  1. activate the “Dev-Mode” (developer-mode) in your Wix-Editor.
  2. On the left side you will see a menu, which shows you all the content of your site-project.
  3. Scroll-down to the very bottom. There you will find your DATABASES (Data-Collections)
  4. Now choose the right DATABASE/COLLECTION and look how it is called?

HOW IT IS CALLED? ----> Then you put exactly this name of your choosen DATABASE into your CODE.

This is the name you are searching for!:grin:

wixData.insert("INPUT-DATABASE-NAME-HERE", toInsert)

something like this…

wixData.insert("Quiz", toInsert)

If the name of your DATABASE is —> Quiz

@russian-dima Thank you, this worked!!

@ar1
You are welcome.
And do not forget to like it, if you really liked it :wink: