Skip to content

Commit

Permalink
fix(db-mongodb): id in querying using a comma-delimited value
Browse files Browse the repository at this point in the history
  • Loading branch information
r1tsuu committed Oct 28, 2024
1 parent 9076926 commit 94d8b8b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/db-mongodb/src/queries/sanitizeQueryValue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ export const sanitizeQueryValue = ({
return { operator: formattedOperator, val: undefined }
}
}
} else if (Array.isArray(val)) {
} else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {
if (typeof val === 'string') {
formattedValue = createArrayFromCommaDelineated(val)
}

formattedValue = formattedValue.reduce((formattedValues, inVal) => {
const newValues = [inVal]
if (!hasCustomID) {
Expand Down
4 changes: 2 additions & 2 deletions test/joins/int.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -618,15 +618,15 @@ describe('Joins Field', () => {
})
})

it('should work id.in querying with joins', async () => {
it('should work id.in command delimited querying with joins', async () => {
const allCategories = await payload.find({ collection: 'categories', pagination: false })

const allCategoriesByIds = await restClient
.GET(`/categories`, {
query: {
where: {
id: {
in: allCategories.docs.map((each) => each.id),
in: allCategories.docs.map((each) => each.id).join(','),
},
},
},
Expand Down

0 comments on commit 94d8b8b

Please sign in to comment.