diff --git a/src/mongoose/sanitizeQueryValue.ts b/src/mongoose/sanitizeQueryValue.ts index 00eedc8f30..3b48086c0d 100644 --- a/src/mongoose/sanitizeQueryValue.ts +++ b/src/mongoose/sanitizeQueryValue.ts @@ -38,7 +38,15 @@ export const sanitizeQueryValue = ({ field, path, operator, val, hasCustomID }: if (val.toLowerCase() === 'false') formattedValue = false; } - if (field.type === 'number' && typeof val === 'string') { + if (['all', 'not_in', 'in'].includes(operator) && typeof formattedValue === 'string') { + formattedValue = createArrayFromCommaDelineated(formattedValue); + + if (field.type === 'number') { + formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal)); + } + } + + if (field.type === 'number' && typeof formattedValue === 'string') { formattedValue = Number(val); } @@ -49,9 +57,6 @@ export const sanitizeQueryValue = ({ field, path, operator, val, hasCustomID }: } } - if (['all', 'not_in', 'in'].includes(operator) && typeof formattedValue === 'string') { - formattedValue = createArrayFromCommaDelineated(formattedValue); - } if (['relationship', 'upload'].includes(field.type)) { if (val === 'null') { diff --git a/test/collections-rest/int.spec.ts b/test/collections-rest/int.spec.ts index 6d402a3f5d..37b20cfb6f 100644 --- a/test/collections-rest/int.spec.ts +++ b/test/collections-rest/int.spec.ts @@ -326,6 +326,22 @@ describe('collections-rest', () => { const { doc: updatedDoc } = await client.update({ slug: customIdNumberSlug, id: doc.id, data: { name: 'updated' } }); expect(updatedDoc.name).toEqual('updated'); }); + + it('should allow querying by in', async () => { + const id = 98234698237; + await client.create({ slug: customIdNumberSlug, data: { id, name: 'query using in operator' } }); + + const { result: { docs } } = await client.find({ + slug: customIdNumberSlug, + query: { + id: { + in: `${id}, ${2349856723948764}`, + }, + }, + }); + + expect(docs).toHaveLength(1); + }); }); });