-
Notifications
You must be signed in to change notification settings - Fork 3.4k
feat: add findDistinct operation
#13102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
📦 esbuild Bundle Analysis for payloadThis analysis was generated by esbuild-bundle-analyzer. 🤖
Largest pathsThese visualization shows top 20 largest paths in the bundle.Meta file: packages/next/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_index.json, Out file: esbuild/index.js
Meta file: packages/payload/meta_shared.json, Out file: esbuild/exports/shared.js
Meta file: packages/richtext-lexical/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_client.json, Out file: esbuild/exports/client_optimized/index.js
Meta file: packages/ui/meta_shared.json, Out file: esbuild/exports/shared_optimized/index.js
DetailsNext to the size is how much the size has increased or decreased compared with the base branch of this PR.
|
DanRibbens
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this have updates to the REST and GraphQL docs?
For now the REST API endpoint is disabled and there's no GraphQL. I was thinking that we might not need that |
Supports grouping documents by specific fields within the list view. For example, imagine having a "posts" collection with a "categories" field. To report on each specific category, you'd traditionally filter for each category, one at a time. This can be quite inefficient, especially with large datasets. Now, you can interact with all categories simultaneously, grouped by distinct values. Here is a simple demonstration: https://github.com/user-attachments/assets/0dcd19d2-e983-47e6-9ea2-cfdd2424d8b5 Enable on any collection by setting the `admin.groupBy` property: ```ts import type { CollectionConfig } from 'payload' const MyCollection: CollectionConfig = { // ... admin: { groupBy: true } } ``` This is currently marked as beta to gather feedback while we reach full stability, and to leave room for API changes and other modifications. Use at your own risk. Note: when using `groupBy`, bulk editing is done group-by-group. In the future we may support cross-group bulk editing. Dependent on #13102 (merged). --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210774523852467 --------- Co-authored-by: Paul Popus <[email protected]>
…irtual fields (#14026) This adds support for using `findDistinct` #13102 on fields: * Nested to a relationship, for example `category.title` * Virtual fields that are linked to relationships, for example `categoryTitle` ```tsx const Category: CollectionConfig = { slug: 'categories', fields: [ { name: 'title', type: 'text', }, ], } const Posts: CollectionConfig = { slug: 'posts', fields: [ { name: 'category', type: 'relationship', relationTo: 'categories', }, { name: 'categoryTitle', type: 'text', virtual: 'category.title', }, ], } // Supported now const relationResult = await payload.findDistinct({ collection: 'posts', field: 'category.title' }) // Supported now const virtualResult = await payload.findDistinct({ collection: 'posts', field: 'categoryTitle' }) ```
Adds a new operation findDistinct that can give you distinct values of a field for a given collection
Example:
Assume you have a collection posts with multiple documents, and some of them share the same title:
You can now retrieve all unique title values using findDistinct:
You can also limit the number of distinct results:
You can also pass a
wherequery to filter the documents.