count() isEmpty values

Hi,

I’ve got a collection with 445 records and 11 fields/columns. One of the fields is ‘language’. For each and every of the 445 collection records, the language field has some value. None is empty . So I wrote this below to get the number of empty fields (for debugging purposes):

import wixData from 'wix-data';
wixData.query("LawDatabase")
  .isEmpty("language")
  .count()
  .then( (num) => {
 let numberOfItems = num;
    console.log("Language field has ", num, "empty cells.")
    $w("#text39").text = num.toString()
  } )  ;

Instead, the code above returns the number 445 instead of 0, so it returns not empty fields. If I change .isEmpty to .isNotEmpty, then I get 0, which is exactly the opposite.

Would you please tell me why?

Where did you test it ?

LIVE or PREVIEW ?

Both DATABASES are synced ?

This code works just fine for me…

import wixData from 'wix-data';

$w.onReady(function () {
    wixData.query("Team")
    .isNotEmpty("status") //---> RESULT = 7 (i have 7 rows and all filled with data)
    .count()
    .then( (num) => {
 let numberOfItems = num;
        console.log("Selected field has ", num, "empty cells.")
    });
});

and when i change back to…

 .isEmpty("status") ---> RESULT = 0

…it also works like it should…

@russian-dima This is the expected.

But it’s not happening to me. As a matter of fact, it works with some fields but not all. What would you say on this one? And yes I’m in Live.

" Comments" is text field type. The isEmpty works correctly. It counts exactly all cells that have data in them and if I add something/or delete something in Live, the change is depicted when refreshing the page. All good.
wixData.query(“LawDatabase”)
.isEmpty(“comments”)
.count()
.then( (num) => {
let numberOfItems = num;
console.log(“Comments field has “, num, “empty cells.”)
$w(”#text11”).text = num.toString()
} ) ;

“Language” is also text field type. THIS ONE DOES NOT WORK. If I delete a value, this does not reflect to total number. It’s still 445, not 444.
wixData.query(“LawDatabase”)
.isEmpty(“Language”)
.count()
.then( (num) => {
let numberOfItems = num;
console.log(“Language field has”, num, “empty cells.”)
$w(“#text25”).text = num.toString()
});

@gemats Sorry here i am out, i do not know your database.
Here you are on your own.

Do some testings, perhaps you will find the reason for this behaviour.

@russian-dima If you’re kind enough, only one more clue:


These are all my DB’s fields. With red you have all fields that are NOT working, but strangely, all these fields are completed, no blanks.

With green, there are the 4 fields that are working properly. I can add/delete values and the change is shown. Can you think something about it? The problematic fields all have in common the fact that they all have values in all rows…

@gemats
Sorry i really don’t have any idea to this strange behaviour, perhaps someone like @jonatandor35 could help out.

Could it be something with refenced fields? You mentioned it in some of your posts.
Could it be something with the type of the fields? But you already said, that “languages” is a “Text-Field” (STRING-Field) and it also do not work.

STRANGE!

By the way, could you solve your “INCLUDE-PROBLEM” ?

@russian-dima
By the way, could you solve your “INCLUDE-PROBLEM” ?


Unfortunately not. I just have copied the referenced values to a field next to it, a tags fields to allow me use multiple values and I work with the tags field which is more… obedient! ;-). Thank you for asking!!

@gemats
Ok. Yes, include is not the most simple one to get use of and also not the most comfortable way (my opinion). But my thoughts could be, because i do not use it, so i am also not very expirienced with it.

But as i always say: “Many roads lead to Rome”

This line is wrong:

  .isEmpty("Language")

A field key in Wix collections never starts with a capital letter, so maybe you used the field label instead or just misspelled the field key, but you should fix it.

P.S. in one of your posts you spelled it correctly while in another one you spelled it wrong, So check your code.

…yes, apparently in some cases I used the field labels instead of field keys… Thank you very much. Problem solved.

You’re welcome :slight_smile:

@jonatandor35
Yes i saw this big Capital letter, too, but at his first post everything was ok…

import wixData from 'wix-data';
wixData.query("LawDatabase")
  .isEmpty("language") <--------------------- ???
  .count()
  .then( (num) => {
 let numberOfItems = num;
    console.log("Language field has ", num, "empty cells.")
    $w("#text39").text = num.toString()
  } )  ;

Ok, i did not really understand now what was the real reason for the failure, but i understand why my testings were ok :grin:.

P.S.: @ J.D. THANKS for clarifying and helping out! :kissing_heart: