Database query only returns a 0. (SOLVED)

Hi All,

I would like to say right off the bat that I am very new to Wix code and have very limited knowledge but am doing my best. I have been spending a solid afternoon on this problem and am about to throw this computer out of the window.

The idea is simple, query the database called ‘answers’ and search for the string ‘Serial Cleaner’ in the ‘Concept’ column. Then count those entries and convert to a string for display in a text object.

This all works fine except the text object returns 0 instead of the 2 items I have in that column.

Here is the code I am using:

import wixData from ‘wix-data’;
// …
export function text12_viewportEnter(event, $w) {

wixData.query(“answers”)
.eq(“Concept”,“Serial Cleaner”)
.count()
.then( (num) => {
let numberOfItems = num;

     $w("#text12").text = "" + num; 

} )
. catch ( (error) => {
let errorMsg = error.message;
let code = error.code;
} );
}

Any help would be greatly appreciated.

Hello

Try using:

  let numberOfItems = num.items 

It should work this way.

best
Massa

Hi Massa,

I have just given that a try but it still returns the number 0.

What am I missing? Is it something to do with the Database itself?

I have attached a screenshot.

Hi Joshua,

The structure of the query looks fine. The only way I could break it and get 0 as the result on a collection of mine was to change the field name to not be case-sensitive. Any chance that the true field name of “Concept” is “concept”? In this example below the true field name (key) that JavaScript honors is highlighted.

Lifesaver!