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 */ /** 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 disableIndexHints?: boolean
migrationDir?: string migrationDir?: string
/** Set to true to evaluate null field values as existing */
nullFieldValuesNotExist?: boolean
transactionOptions?: TransactionOptions | false transactionOptions?: TransactionOptions | false
/** The URL to connect to MongoDB or false to start payload and prevent connecting */ /** The URL to connect to MongoDB or false to start payload and prevent connecting */
url: false | string url: false | string
@@ -93,6 +95,7 @@ export function mongooseAdapter({
connectOptions, connectOptions,
disableIndexHints = false, disableIndexHints = false,
migrationDir: migrationDirArg, migrationDir: migrationDirArg,
nullFieldValuesNotExist = true,
transactionOptions = {}, transactionOptions = {},
url, url,
}: Args): MongooseAdapterResult { }: Args): MongooseAdapterResult {
@@ -103,6 +106,8 @@ export function mongooseAdapter({
return createDatabaseAdapter<MongooseAdapter>({ return createDatabaseAdapter<MongooseAdapter>({
name: 'mongoose', name: 'mongoose',
nullFieldValuesNotExist,
// Mongoose-specific // Mongoose-specific
autoPluralization, autoPluralization,
collections: {}, collections: {},

View File

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

View File

@@ -1,3 +1,4 @@
import type { Payload } from 'payload'
import type { Field, TabAsField } from 'payload/types' import type { Field, TabAsField } from 'payload/types'
import mongoose from 'mongoose' import mongoose from 'mongoose'
@@ -8,6 +9,7 @@ type SanitizeQueryValueArgs = {
hasCustomID: boolean hasCustomID: boolean
operator: string operator: string
path: string path: string
payload: Payload
val: any val: any
} }
@@ -16,6 +18,7 @@ export const sanitizeQueryValue = ({
hasCustomID, hasCustomID,
operator, operator,
path, path,
payload,
val, val,
}: SanitizeQueryValueArgs): { }: SanitizeQueryValueArgs): {
operator?: string 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 } return { operator: formattedOperator, val: formattedValue }