Count from database and add to field on page

I have a collection named PG course data collection, from which I’d like to count the number of items and add it to a field #serialNumber on the page. The following code is not working. Any idea what’s wrong? :v:

wixData.query(“PG course data collection”)
.find()
.then( (num) => {
let numberOfItems = num;
$w(“#serialNumber”).value = “”+num+1;
console.log(num);
} )
.catch( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
})

Much easier to use the count() function and not find(). Something like this:

wixData.query("collection")
  .count()
  .then( (num) => {
    let numberOfItems = num + 1;
    $w("#serialNumber").value = "" + numberOfItems;
  } )
  .catch( (error) => {
    let errorMsg = error.message;
    let code = error.code;
  } );

Thanks, @yisrael-wix . Still, the code didn’t work. Then after a break, I found the “collection” name has to be without spaces.:roll_eyes::man_facepalming: Working fine now.:v:t2: