Hi guys,
I don’t know why, but every time I run a query with .distinct() I get an error saying it’s not a function. Really frustrating.
I’m wondering if I’m doing something wrong.
Does the .distinct() work for you?
Thanks,
J.D.
Hi guys,
I don’t know why, but every time I run a query with .distinct() I get an error saying it’s not a function. Really frustrating.
I’m wondering if I’m doing something wrong.
Does the .distinct() work for you?
Thanks,
J.D.
Anyone?
How are you using it? Can you show a code segment?
Very simple:
wixData.query("CollectionName")
.eq("field1", value)
.distinct("field2")
.find()
.then((res) => { })
I just wanted to know if it worked to anyone else (and then I’ll try to locate the problem).
Thanks,
@jonatandor35 I believe that the error is actually from the example code snippet… distinct() is not used together with .find(). I’ll notify the docs team.
So, it should be something like this:
wixData.query("CollectionName")
.eq("field1", value)
.distinct("field2")
.then((res) => { })
I tried a query like this as a test and it worked fine.
I hope this helps.
@yisrael-wix I see. Thanks!
Can you please explain why distinct() and find() are not used together? Does the distinct() include the find() functionality?
P.S. I mentioned in another post that the example in the documentation also includes a typo distict() instead of distinct(). Maybe you’d like to forward it to the relevant people.
@jonatandor35 You got it - distinct() does a find() based on a specified field.
And the docs team got a whole pile of stuff from me regarding this issue: what exactly is distinct(), what is the behavior, not used with find(), spelling, etc.
Thanks
@yisrael-wix
Thanks !!
@jonatandor35 distinct is running the query and returning a promise of the result.
The reasoning is that distinct is a special type of query, and unlike find returns a different result.
.find() returns a result with full items in it - as objects
.distinct() returns a result with only the distinct field value - not objects.
@yoav-wix ha! good to know.
and what is expected to happen if I use .limit(20) with distinct()? Will it first pull the first 20 records and only then run the distinct() on these 20? Or will it find the distinct objects and then return the first 20 of them?