fix(db-mongodb): totalDocs with joins (#9056)
### What? Fixes issue with incorrect `totalDocs` value when an aggregation is used for `find`. Previously, `limit: 5` for example always returned `totalDocs: 5`. ### Why? `totalDocs` must be returned correctly. ### How? Removes `$limit` from the pipeline, as `Model.aggregatePaginate` handles it by itself.
This commit is contained in:
@@ -831,6 +831,28 @@ describe('Joins Field', () => {
|
||||
expect(res.group.relatedPosts.docs).toBeDefined()
|
||||
expect(res.group.camelCasePosts.docs).toBeDefined()
|
||||
})
|
||||
|
||||
it('should have correct totalDocs', async () => {
|
||||
for (let i = 0; i < 50; i++) {
|
||||
await payload.create({ collection: categoriesSlug, data: { name: 'totalDocs' } })
|
||||
}
|
||||
|
||||
const count = await payload.count({
|
||||
collection: categoriesSlug,
|
||||
where: { name: { equals: 'totalDocs' } },
|
||||
})
|
||||
expect(count.totalDocs).toBe(50)
|
||||
|
||||
const find = await payload.find({
|
||||
collection: categoriesSlug,
|
||||
limit: 5,
|
||||
where: { name: { equals: 'totalDocs' } },
|
||||
})
|
||||
expect(find.totalDocs).toBe(50)
|
||||
expect(find.docs).toHaveLength(5)
|
||||
|
||||
await payload.delete({ collection: categoriesSlug, where: { name: { equals: 'totalDocs' } } })
|
||||
})
|
||||
})
|
||||
|
||||
async function createPost(overrides?: Partial<Post>, locale?: Config['locale']) {
|
||||
|
||||
Reference in New Issue
Block a user