Description
Describe the Bug
On the SQL adapters, the not_like operator does not exclude documents whose value contains the given string. It only excludes documents whose value is exactly equal to it, so it behaves like a case-insensitive not_equals.
await payload.create({ collection: 'posts', data: { title: 'hello world' } })
await payload.create({ collection: 'posts', data: { title: 'goodbye' } })
const { docs } = await payload.find({
collection: 'posts',
where: { title: { not_like: 'hello' } },
})
// Expected: ['goodbye']
// Actual (SQLite / D1 / Postgres): ['hello world', 'goodbye']The MongoDB adapter handles this as expected: it splits the value into words and excludes documents that contain any of them ($and of $not: { $regex: word, $options: 'i' }), i.e. the negation of like. #11326, which added not_like, also describes it as "just as a negative to like".
Cause
In packages/drizzle/src/queries/parseParams.ts, like has its own branch that wraps every word in %...%. There is no equivalent branch for not_like, so it falls through to sanitizeQueryValue and adapter.operators.not_like(column, value) is called with the raw value. The resulting SQL is NOT LIKE 'hello' (NOT ILIKE on Postgres) without wildcards.
The existing test should query not_like on value in test/fields/int.spec.ts only uses an exact value (not_like: 'cat-unique-test'), so it passes despite this.
The same code is present on both 3.x and main.
Link to the code that reproduces this issue
Reproduction Steps
- Check out the
repro/not-like-partialbranch (based on3.x). It only adds one test totest/_community/int.spec.ts, using the existingpostscollection. - Run
pnpm install. - Run
pnpm test:int:sqlite _community. - The test
not_like should exclude documents that contain the valuefails:
AssertionError: expected [ 'goodbye', 'hello world', …(3) ] to not include 'hello world'
Which area(s) are affected?
db: sqlite, db: d1-sqlite, db: postgres
Environment Info
Binaries:
Node: 24.13.0
Relevant Packages:
payload: 3.92.1
next: 16.3.3
@payloadcms/db-d1-sqlite: 3.92.1
@payloadcms/drizzle: 3.92.1
@payloadcms/graphql: 3.92.1
@payloadcms/richtext-lexical: 3.92.1
react: 19.2.6
react-dom: 19.2.6
Operating System:
Platform: win32
Arch: x64
Version: Windows 11 Pro
Also reproduced on the 3.x branch of this repository (commit 8bbd52e) with PAYLOAD_DATABASE=sqlite.
Activity
chore(drizzle): fix partial not_like matching
chore: test partial not_like queries end to end