Skip to content
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

feat: add count operation to collections #5936

Merged
merged 2 commits into from Apr 21, 2024

Conversation

r1tsuu
Copy link
Contributor

@r1tsuu r1tsuu commented Apr 20, 2024

Description

Copy of #5930 to main branch

Adds operation count that counts the documents that are satisfying the query. Basically find without extra overhead (doesn't run drizzle/mongoose find), only totalDocs.

Usage:

Local API

const result = await payload.count({
  collection: 'users',
  where: {
    role: {
      equals: 'admin',
    },
  },
})
const { totalDocs } = result

REST API

const result = await fetch(`/api/posts/count`).then((res) => res.json())
const { totalDocs } = result

GraphQL

query {
  countPosts(where: { title: { equals: "Hello World" } }) {
    totalDocs
  }
}
  • I have read and understand the CONTRIBUTING.md document in this repository.

Type of change

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Checklist:

  • I have added tests that prove my fix is effective or that my feature works
  • Existing test suite passes locally with my changes
  • I have made corresponding changes to the documentation

@DanRibbens DanRibbens merged commit c380dee into payloadcms:main Apr 21, 2024
33 checks passed
@shuowu
Copy link

shuowu commented Apr 24, 2024

When this feature will be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants