Repository: payloadcms/payload (TypeScript)

Issue:
ID not working in listSearchableFields
### Link to reproduction

pnpm dev admin

### Describe the Bug

If `id` is included in `listSearchableFields`, the expected result is not returned.

### To Reproduce

Using the monorepo,

1. Add `id` to `listSearchableFields` in `test/admin/collections/Posts.ts`
2. `pnpm dev admin`
3. Open Posts list view, try searching for a document using an ID

### Payload Version

2.1.0

### Adapters and Plugins

_No response_
searching id generates error
### Link to reproduction

https://github.com/GeorgeHulpoi/payload-searchable-id

### Describe the Bug

Trying to search an id on search input will generate the following error:

```
[18:12:53] ERROR (payload): Error: Can't use $regex
    at ObjectId.SchemaType.castForQuery (C:\Projects\project\project.api\node_modules\mongoose\lib\schematype.js:1632:13)
    at ObjectId.SchemaType.castForQueryWrapper (C:\Projects\project\project.api\node_modules\mongoose\lib\schematype.js:1603:22)
    at cast (C:\Projects\project\project.api\node_modules\mongoose\lib\cast.js:321:39)
    at cast (C:\Projects\project\project.api\node_modules\mongoose\lib\cast.js:71:18)
    at cast (C:\Projects\project\project.api\node_modules\mongoose\lib\cast.js:71:18)
    at cast (C:\Projects\project\project.api\node_modules\mongoose\lib\cast.js:71:18)
    at cast (C:\Projects\project\project.api\node_modules\mongoose\lib\cast.js:71:18)
    at model.Query.Query.cast (C:\Projects\project\project.api\node_modules\mongoose\lib\query.js:5351:12)
    at model.Query.Query._castConditions (C:\Projects\project\project.api\node_modules\mongoose\lib\query.js:2229:10)
    at model.Query.<anonymous> (C:\Projects\project\project.api\node_modules\mongoose\lib\query.js:2256:8)
```

### To Reproduce

1. Create a item in `Test` collection.
2. Try to search the ID in search input.
3. It should generate the error

### Payload Version

2.1.1

### Adapters and Plugins

MongoDB


Discussion: I've been having the same issue as in this related bug-report: [#4227](https://github.com/payloadcms/payload/issues/4227) Any updates to this? 
A little extra detail:
This only seems to be an issue when searching by ID on collections whose ID's are created automatically by Payload. I have several collections where the ID is created based on required fields of that record and I'm not seeing any issues when searching by ID on those collections.

Possible dupe of https://github.com/payloadcms/payload/issues/4081



Fix (patch):
diff --git a/packages/db-mongodb/src/queries/buildSearchParams.ts b/packages/db-mongodb/src/queries/buildSearchParams.ts
index 59df2b770c6..91ca73cf45a 100644
--- a/packages/db-mongodb/src/queries/buildSearchParams.ts
+++ b/packages/db-mongodb/src/queries/buildSearchParams.ts
@@ -92,7 +92,7 @@ export async function buildSearchParam({
   const [{ field, path }] = paths
 
   if (path) {
-    const formattedValue = sanitizeQueryValue({
+    const { operator: formattedOperator, val: formattedValue } = sanitizeQueryValue({
       field,
       hasCustomID,
       operator,
@@ -125,7 +125,7 @@ export async function buildSearchParam({
               payload,
               where: {
                 [subPath]: {
-                  [operator]: val,
+                  [formattedOperator]: val,
                 },
               },
             })
@@ -183,8 +183,8 @@ export async function buildSearchParam({
       return relationshipQuery
     }
 
-    if (operator && validOperators.includes(operator as Operator)) {
-      const operatorKey = operatorMap[operator]
+    if (formattedOperator && validOperators.includes(formattedOperator as Operator)) {
+      const operatorKey = operatorMap[formattedOperator]
 
       if (field.type === 'relationship' || field.type === 'upload') {
         let hasNumberIDRelation
@@ -227,7 +227,7 @@ export async function buildSearchParam({
         }
       }
 
-      if (operator === 'like' && typeof formattedValue === 'string') {
+      if (formattedOperator === 'like' && typeof formattedValue === 'string') {
         const words = formattedValue.split(' ')
 
         const result = {
diff --git a/packages/db-mongodb/src/queries/sanitizeQueryValue.ts b/packages/db-mongodb/src/queries/sanitizeQueryValue.ts
index 4d28ec14a4b..c36430723d7 100644
--- a/packages/db-mongodb/src/queries/sanitizeQueryValue.ts
+++ b/packages/db-mongodb/src/queries/sanitizeQueryValue.ts
@@ -17,8 +17,9 @@ export const sanitizeQueryValue = ({
   operator,
   path,
   val,
-}: SanitizeQueryValueArgs): unknown => {
+}: SanitizeQueryValueArgs): { operator: string; val: unknown } => {
   let formattedValue = val
+  let formattedOperator = operator
 
   // Disregard invalid _ids
   if (path === '_id' && typeof val === 'string' && val.split(',').length === 1) {
@@ -26,7 +27,7 @@ export const sanitizeQueryValue = ({
       const isValid = mongoose.Types.ObjectId.isValid(val)
 
       if (!isValid) {
-        return undefined
+        return { operator: formattedOperator, val: undefined }
       }
     }
 
@@ -34,7 +35,7 @@ export const sanitizeQueryValue = ({
       const parsedNumber = parseFloat(val)
 
       if (Number.isNaN(parsedNumber)) {
-        return undefined
+        return { operator: formattedOperator, val: undefined }
       }
     }
   }
@@ -123,9 +124,18 @@ export const sanitizeQueryValue = ({
     }
   }
 
+  if (
+    (path === '_id' || path === 'parent') &&
+    operator === 'like' &&
+    formattedValue.length === 24 &&
+    !hasCustomID
+  ) {
+    formattedOperator = 'equals'
+  }
+
   if (operator === 'exists') {
     formattedValue = formattedValue === 'true' || formattedValue === true
   }
 
-  return formattedValue
+  return { operator: formattedOperator, val: formattedValue }
 }
diff --git a/packages/payload/src/admin/components/views/collections/List/index.tsx b/packages/payload/src/admin/components/views/collections/List/index.tsx
index ae57a8777d8..99914cfc507 100644
--- a/packages/payload/src/admin/components/views/collections/List/index.tsx
+++ b/packages/payload/src/admin/components/views/collections/List/index.tsx
@@ -107,13 +107,16 @@ const ListView: React.FC<ListIndexProps> = (props) => {
       if (search) {
         let copyOfWhere = { ...((where as Where) || {}) }
 
-        const searchAsConditions = (listSearchableFields || [titleField?.name]).map((fieldName) => {
-          return {
-            [fieldName]: {
-              like: search,
-            },
-          }
-        }, [])
+        const searchAsConditions = (listSearchableFields || [titleField?.name || 'id']).map(
+          (fieldName) => {
+            return {
+              [fieldName]: {
+                like: search,
+              },
+            }
+          },
+          [],
+        )
 
         if (searchAsConditions.length > 0) {
           const conditionalSearchFields = {