GraphQL & API Distinct Data

Hi Sebastian,

I have a schema. I have fields for name, surname and title. There are about 20k data on this schema. I need to filter and fetch all unique title field.

for example: https://www.w3schools.com/sql/sql_distinct.asp

Thank you

And what should happen with the non-distinct values? I mean the other fields.

Example Datas;

Name Surname Title
Steve Dainty Doctor
Rosa White Doctor
Angelina Pride Computer Engineer
Jack Carney Lawyer

Select Distinct(title)
Result:

Title
Doctor
Computer Engineer
Lawyer

I expect it to not fetch other data.

@Sebastian I’m waiting for your good news.

Thank you.

I will have a look to it this Friday or next week.

1 Like

i’m waiting… thank you.

I have not promised to implement it …

Can you describe me your use cases, the point is:

  1. If you have a high number of entities you will never get good performance, because you need an index for that, for example elastic search.
  2. If you have a medium number of entities and this query is part of a migration or something that does not run very often, it does not make sense to implement it, because the performance characteristics of a manual query are good enough.
  3. If you have a medium number of entities (20k would be the absolute limit here), you can implement it, but you have to do it on the database level. But with 20k you would probably not get a good performance anyway.

Hi Sebastian,

In fact, an improvement that can increase the quality of these queries may be needed by many people, such as filtering and returning unique values. I think that querying it directly at database level with an api and graphql method will give the best results. Your comments are important here. This will also simplify many issues in terms of directly receiving and using data for frontend etc. I also think that the development phase will not take much time. but still you know…

thanks for everything

You have not answered my question yet.

Actually, the third option you said is appropriate. Well, while creating the fields on the schema, if we mark them as index and create a directory on the mongo side, wouldn’t it provide performance for the related fields, and it would be nice with such a feature.

Create Schemas > Create Field Popup> ([X] Indexed) >> Mongo Index
Is such a feature possible?
It would be great if distinct is added on it.

You still have not answered my question. What is your use case?

If you need it for a website frontend, I am not sure if the performance will be good enough.
If you need it for another operation, like maintenance, it is not worth to implement this feature.

I recommend to put this data into an algolia index for that.

Yes and no.

There are so many problems with that (especially with the cloud):

  1. How do you know that you need an index? You have to provide all the tooling that is also available to database administrators, because you need a deep understanding of the queries being made and the data structure to decide which index is the best. So you need a query analyzer, a list of slow queries and some charts like index size and so on to make a good decision.

  2. Because indexes are not isolated (they live on the same machine), they basically fight for resources. If you create too many indexes the performance will become slower and therefore you have to isolate the apps from each other. Which means that each app would need its own database cluster and its own server cluster. Because the costs would explode otherwise, you would need a shared tier (like now) for the free plans and then migrate the data to dedicated servers for paid tiers. The paid tiers would probably in the pricing range of 150€, 500€, 800€. So very similar to contentful for example.