fix(db-mongodb): fallback version when not selected (#12158)

When doing `payload.db.queryDrafts` with `select` without `version`, or
simply your select looks like:
`select: { version: { nonExistingField: true } }` - the `queryDrafts`
function will crash because it tries to access the `version` field.
This PR adds a fallback.
This commit is contained in:
Sasha
2025-04-18 21:43:53 +03:00
committed by GitHub
parent fdff5871f6
commit 6dc61ae642
2 changed files with 12 additions and 1 deletions

View File

@@ -2403,4 +2403,15 @@ describe('database', () => {
payload.db.allowAdditionalKeys = false
})
it('should not crash when the version field is not selected', async () => {
const customID = await payload.create({ collection: 'custom-ids', data: {} })
const res = await payload.db.queryDrafts({
collection: 'custom-ids',
where: { parent: { equals: customID.id } },
select: { parent: true },
})
expect(res.docs[0].id).toBe(customID.id)
})
})