diff --git a/packages/db-mongodb/src/queries/sanitizeQueryValue.ts b/packages/db-mongodb/src/queries/sanitizeQueryValue.ts index 8d0d1e4f34..037028969b 100644 --- a/packages/db-mongodb/src/queries/sanitizeQueryValue.ts +++ b/packages/db-mongodb/src/queries/sanitizeQueryValue.ts @@ -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) { diff --git a/test/joins/int.spec.ts b/test/joins/int.spec.ts index 4fea558289..119b0ebd64 100644 --- a/test/joins/int.spec.ts +++ b/test/joins/int.spec.ts @@ -609,6 +609,24 @@ describe('Joins Field', () => { expect(response.data.Category.relatedPosts.docs[0].title).toStrictEqual('test 3') }) }) + + 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).join(','), + }, + }, + }, + }) + .then((res) => res.json()) + + expect(allCategories.totalDocs).toBe(allCategoriesByIds.totalDocs) + }) }) async function createPost(overrides?: Partial, locale?: Config['locale']) {