payloadcms/payload

Bug Report: "like" filter returns unexpected results in 3.0

Opened this issue · 1 comments

Describe the Bug

The like filter does not function as expected.

Link to the code that reproduces this issue

N/A

Reproduction Steps

  1. Create a new 3.0 project
pnpx create-payload-app@beta
  1. Create the Script src/temp.ts
import { getPayload } from 'payload'
import config from '@payload-config'

const temp = async () => {
    const payload = await getPayload({ config })

    const user = await payload.create({
        collection: 'users',
        data: {
            email: "abc@example.com",
            password: "abc"
        },
    })
    console.log(`user: ${JSON.stringify(user, null, 2)}`)

    const users = await payload.find({
        collection: 'users',
        where: {
            email: {
                like: 'b%',
            },
        },
        depth: 0,
    })
    console.log(`users: ${JSON.stringify(users, null, 2)}`)
}

await temp()
  1. Start the app
pnpm run dev
  1. Run the script
npx payload run src/temp.ts

Expected Behavior:
No records should be found because the created record's email ("abc@example.com") does not start with b.

Actual Behavior:
The script returns the created record whose email starts with a, despite the filter condition.

Console Output:

user: {
  "id": 1,
  "updatedAt": "2024-11-08T09:49:23.273Z",
  "createdAt": "2024-11-08T09:49:23.273Z",
  "email": "abc@example.com",
  "loginAttempts": 0
}
users: {
  "docs": [
    {
      "id": 1,
      "updatedAt": "2024-11-08T09:49:23.273Z",
      "createdAt": "2024-11-08T09:49:23.273Z",
      "email": "abc@example.com",
      "loginAttempts": 0
    }
  ],
  "hasNextPage": false,
  "hasPrevPage": false,
  "limit": 10,
  "nextPage": null,
  "page": 1,
  "pagingCounter": 1,
  "prevPage": null,
  "totalDocs": 1,
  "totalPages": 1
}

Which area(s) are affected? (Select all that apply)

Not sure

Environment Info

N/A

Please add a reproduction in order for us to be able to investigate.

Depending on the quality of reproduction steps, this issue may be closed if no reproduction is provided.

Why was this issue marked with the invalid-reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository created with create-payload-app@beta -t blank or a forked/branched version of this repository with tests added (more info in the reproduction-guide).

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

Please test your reproduction against the latest version of Payload to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

Useful Resources