Compare commits

...

3 Commits

Author SHA1 Message Date
Kendell Joseph
501022991f feat: updates exist operator to retrieve null as a value that exists when flag is enabled 2024-03-01 16:44:54 -05:00
Kendell Joseph
53600c7352 feat: adds flag for null field values using the mongoose adapter 2024-03-01 16:42:19 -05:00
Kendell Joseph
76c1b23729 chore: send config to sanitize step 2024-03-01 16:41:28 -05:00
3 changed files with 17 additions and 0 deletions

View File

@@ -49,6 +49,8 @@ export interface Args {
/** Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false */
disableIndexHints?: boolean
migrationDir?: string
/** Set to true to evaluate null field values as existing */
nullFieldValuesNotExist?: boolean
transactionOptions?: TransactionOptions | false
/** The URL to connect to MongoDB or false to start payload and prevent connecting */
url: false | string
@@ -93,6 +95,7 @@ export function mongooseAdapter({
connectOptions,
disableIndexHints = false,
migrationDir: migrationDirArg,
nullFieldValuesNotExist = true,
transactionOptions = {},
url,
}: Args): MongooseAdapterResult {
@@ -103,6 +106,8 @@ export function mongooseAdapter({
return createDatabaseAdapter<MongooseAdapter>({
name: 'mongoose',
nullFieldValuesNotExist,
// Mongoose-specific
autoPluralization,
collections: {},

View File

@@ -102,6 +102,7 @@ export async function buildSearchParam({
hasCustomID,
operator,
path,
payload,
val,
})

View File

@@ -1,3 +1,4 @@
import type { Payload } from 'payload'
import type { Field, TabAsField } from 'payload/types'
import mongoose from 'mongoose'
@@ -8,6 +9,7 @@ type SanitizeQueryValueArgs = {
hasCustomID: boolean
operator: string
path: string
payload: Payload
val: any
}
@@ -16,6 +18,7 @@ export const sanitizeQueryValue = ({
hasCustomID,
operator,
path,
payload,
val,
}: SanitizeQueryValueArgs): {
operator?: string
@@ -174,6 +177,14 @@ export const sanitizeQueryValue = ({
}
}
}
if (!payload.db.nullFieldValuesNotExist) {
return {
rawQuery: {
$or: [{ [path]: { $exists: true } }, { [path]: { $eq: null } }],
},
}
}
}
return { operator: formattedOperator, val: formattedValue }