From c96985be0c14fcff768e036de96ebef3caa24d1c Mon Sep 17 00:00:00 2001 From: James Date: Mon, 25 Jul 2022 16:48:45 -0400 Subject: [PATCH] fix: #806, allow partial word matches using 'like' operator --- src/mongoose/sanitizeFormattedValue.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoose/sanitizeFormattedValue.ts b/src/mongoose/sanitizeFormattedValue.ts index e49fd0791e..102ba11be4 100644 --- a/src/mongoose/sanitizeFormattedValue.ts +++ b/src/mongoose/sanitizeFormattedValue.ts @@ -98,7 +98,7 @@ export const sanitizeQueryValue = (schemaType: SchemaType, path: string, operato if (operator === 'like' && typeof formattedValue === 'string') { const words = formattedValue.split(' '); const regex = words.reduce((pattern, word, i) => { - return `${pattern}(?=.*\\b${word}\\b)${i + 1 === words.length ? '.+' : ''}`; + return `${pattern}(?=.*\\b${word}.*\\b)${i + 1 === words.length ? '.+' : ''}`; }, ''); formattedValue = { $regex: new RegExp(regex), $options: 'i' };