Trying to retrieve the data from the collection in spite the data being present, data is not retrieved and results.items.length ==0.

Hello Leslie,

and where is the code? ? ? :grin:

import wixData from ‘wix-data’;
$w.onReady(function () {
//TODO:
});
export function btnLogin_click(event) {
wixData.query(“Partners_ID”)
.eq(“UserID”, “9999999999”)
.find()
.then((results) =>{
if (results.items.length == 0) {
console.log(“Invalid User ID”)
} else {
let firstItem = results.items[0];
console.log()
}
}
);
}

Hello Leslie,

try this one…

export function button1_click(event) {btnLogin_click()}

export function btnLogin_click(event) {

    wixData.query("Partners_ID")
    .eq("UserID", "9999999999")
    .find()
    .then((results) =>{

 if (results.items.length > 0) {
 let firstItem = results.items[0];
                console.log("A user was found")
                console.log(firstItem)
            } else {
                console.log("Invalid User ID")
            }   
        }
    );
}

To bring this code-snipet to work, you will need a button on your page, called —> “button1” which is connected to the code with an —> “onClick-Event”.

Good luck.

Thanks for your response…
however


“btnLogin_click” is getting called as the message “Invalid User ID” is printed on console.

Are there any db access credentials that come in force for retrieving the records?

For DB-permissions look here…

Check if your inputs are all alright and written right in code.

  1. “Partners_ID” —> Database
  2. “UserID” —> Reference
  3. “9999999999” —> item

This is the setting that we have used

Hi leslie.varghese

First things first, for comparison in JavaScript, we use triple equal ( === ) to mean equal, and ( !== ) to mean not equal.

Try something like this:

.then((results) =>{
	if (results.items.length > 0) {
		let firstItem = results.items[0];
		console.log(firstItem)		
	} else {		
		console.log("Invalid User ID")
	}	
}

@Ahmad: Hello Ahmad, can’t see any differenz to my code (above)
Did you change something?

export function button1_click(event) {btnLogin_click()}

export function btnLogin_click(event) {
    wixData.query("Partners_ID")
    .eq("UserID", "9999999999")
    .find()
    .then((results) =>{
         if (results.items.length > 0) {
             let firstItem = results.items[0];
             console.log("A user was found")
             console.log(firstItem)
          } 
          else {
              console.log("Invalid User ID")
          }   
        }
    );
}