Shouldn't it be number of rows matched the query?
# help
d
Shouldn't it be number of rows matched the query?
b
If you didn't pass anything in the
count
option you probably will get null for count here. https://supabase.io/docs/reference/javascript/select#querying-with-count-option
However, you can just look at
data.length()
to get your count.
d
Yes, it is
null
so I ended up using
data.length
b
the
count
option can be used to retrieve just the count of records but no data (if you just want to see how many records there would be but don't want the data yet)
d
Yes I want to get count only.
b
let me look for that syntax, I forget what it is, hold on
d
Perfect, thanks for the link 🙂
Copy code
js
const { data, error, count } = await supabase
  .from('cities')
  .select('name', { count: 'exact' }) // if you don't want to return any rows, you can use { count: 'exact', head: true }
I got it in the link you send \:)
b
yeah, but that will still return data I think.
d
oh
b
Copy code
const { data, error, count } = await this.supabase
      .from('game_data')
      .select('correct', {count: 'exact', head: true})
      .eq('correct', 1);
Here I am asking for the count of records where the
correct
field == 1
d
I just want to check if there is atleast one row where userId column value is
1234
b
but using
head: true
returns just the count and no data
d
Cool
b
so this format should do it for you.
d
Is there any other way for this?
Apart from what I am doing right now i.e. getting count?
b
I'm not a fan of this syntax so I expect we'll change to a new
.count()
method sometimes soon.
d
That'll be really great
b
No copy my query and change it look for what you want and that should do it, and should be fast and not return anything but the count.
d
Thank you for the help 😄
b
no problem
oh, you don't need to select any column, or select '*' would be fine
doesn't matter since you're just getting count 🙂
d
Yes, I had selected single column to save bandwidth by not fetching the whole row
but now I can use *