// Function to return the number of items in my collection which is 699//
// However it returns the promise from the wixData.query what am i doing wrong ?// // I realise I am doing something stupid but cannot figuer it out. I would like to know why not just the solution if possible.// // If someone would be kind enough to help please , I would be very grateful.//
// Its something I think with the call to wixData.query function , I may well be wrong.// //Thank you for taking time help a very frustrated me, please don't laugh to much I am a beginner) //
import wixData from 'wix-data'; var count =fetchNumberOfRecords(count) // I expected numberOfItems 699 retured. // console.log("After function call = ",count); // It returns 'Promise<> ' ? Not 699 //
function fetchNumberOfRecords (param){ return wixData.query("Contacts2",count) .count() .then( (num) => { let numberOfItems = num; console.log("numberOfItems fund value = ",numberOfItems); // Value correct 699// return(numberOfItems); // I expected this to return value 699// } ) .catch( (error) => { let errorMsg = error.message; let code = error.code; } ); }
That's because fetchNumberOfRecords is a promise and you should wait for its resolution before you can log it to the console.
something like:
fetchNumberOfRecords(count) .then(res => console.log("After function call = ", res));