diff --git a/packages/db-mongodb/src/index.ts b/packages/db-mongodb/src/index.ts index a8e74a1b125..3c77aa8ca31 100644 --- a/packages/db-mongodb/src/index.ts +++ b/packages/db-mongodb/src/index.ts @@ -1,7 +1,17 @@ import type { CollationOptions, TransactionOptions } from 'mongodb' import type { MongoMemoryReplSet } from 'mongodb-memory-server' import type { ClientSession, Connection, ConnectOptions, QueryOptions } from 'mongoose' -import type { BaseDatabaseAdapter, DatabaseAdapterObj, Payload, UpdateOneArgs } from 'payload' +import type { + BaseDatabaseAdapter, + DatabaseAdapterObj, + Payload, + TypeWithID, + TypeWithVersion, + UpdateGlobalArgs, + UpdateGlobalVersionArgs, + UpdateOneArgs, + UpdateVersionArgs, +} from 'payload' import fs from 'fs' import mongoose from 'mongoose' @@ -135,7 +145,16 @@ declare module 'payload' { }[] sessions: Record transactionOptions: TransactionOptions + updateGlobal: >( + args: { options?: QueryOptions } & UpdateGlobalArgs, + ) => Promise + updateGlobalVersion: ( + args: { options?: QueryOptions } & UpdateGlobalVersionArgs, + ) => Promise> updateOne: (args: { options?: QueryOptions } & UpdateOneArgs) => Promise + updateVersion: ( + args: { options?: QueryOptions } & UpdateVersionArgs, + ) => Promise> versions: { [slug: string]: CollectionModel } diff --git a/packages/db-mongodb/src/updateGlobal.ts b/packages/db-mongodb/src/updateGlobal.ts index 4016a33ee16..0b0f36fc96e 100644 --- a/packages/db-mongodb/src/updateGlobal.ts +++ b/packages/db-mongodb/src/updateGlobal.ts @@ -1,3 +1,4 @@ +import type { QueryOptions } from 'mongoose' import type { PayloadRequest, UpdateGlobal } from 'payload' import type { MongooseAdapter } from './index.js' @@ -9,12 +10,13 @@ import { withSession } from './withSession.js' export const updateGlobal: UpdateGlobal = async function updateGlobal( this: MongooseAdapter, - { slug, data, req = {} as PayloadRequest, select }, + { slug, data, options: optionsArgs = {}, req = {} as PayloadRequest, select }, ) { const Model = this.globals const fields = this.payload.config.globals.find((global) => global.slug === slug).fields - const options = { + const options: QueryOptions = { + ...optionsArgs, ...(await withSession(this, req)), lean: true, new: true, diff --git a/packages/db-mongodb/src/updateGlobalVersion.ts b/packages/db-mongodb/src/updateGlobalVersion.ts index 4588ef5951a..a83a85ad480 100644 --- a/packages/db-mongodb/src/updateGlobalVersion.ts +++ b/packages/db-mongodb/src/updateGlobalVersion.ts @@ -1,3 +1,5 @@ +import type { QueryOptions } from 'mongoose' + import { buildVersionGlobalFields, type PayloadRequest, @@ -17,6 +19,7 @@ export async function updateGlobalVersion( id, global: globalSlug, locale, + options: optionsArgs = {}, req = {} as PayloadRequest, select, versionData, @@ -30,7 +33,8 @@ export async function updateGlobalVersion( this.payload.config.globals.find((global) => global.slug === globalSlug), ) - const options = { + const options: QueryOptions = { + ...optionsArgs, ...(await withSession(this, req)), lean: true, new: true, diff --git a/packages/db-mongodb/src/updateVersion.ts b/packages/db-mongodb/src/updateVersion.ts index f199d4c7f1e..b79f6727c75 100644 --- a/packages/db-mongodb/src/updateVersion.ts +++ b/packages/db-mongodb/src/updateVersion.ts @@ -1,3 +1,5 @@ +import type { QueryOptions } from 'mongoose' + import { buildVersionCollectionFields, type PayloadRequest, type UpdateVersion } from 'payload' import type { MongooseAdapter } from './index.js' @@ -8,7 +10,16 @@ import { withSession } from './withSession.js' export const updateVersion: UpdateVersion = async function updateVersion( this: MongooseAdapter, - { id, collection, locale, req = {} as PayloadRequest, select, versionData, where }, + { + id, + collection, + locale, + options: optionsArgs = {}, + req = {} as PayloadRequest, + select, + versionData, + where, + }, ) { const VersionModel = this.versions[collection] const whereToUse = where || { id: { equals: id } } @@ -17,7 +28,8 @@ export const updateVersion: UpdateVersion = async function updateVersion( this.payload.collections[collection].config, ) - const options = { + const options: QueryOptions = { + ...optionsArgs, ...(await withSession(this, req)), lean: true, new: true, diff --git a/packages/payload/src/database/types.ts b/packages/payload/src/database/types.ts index ab175f86f7d..44d62fdb849 100644 --- a/packages/payload/src/database/types.ts +++ b/packages/payload/src/database/types.ts @@ -283,6 +283,10 @@ export type FindGlobalArgs = { export type UpdateGlobalVersionArgs = { global: string locale?: string + /** + * Additional database adapter specific options to pass to the query + */ + options?: Record req: PayloadRequest select?: SelectType versionData: T @@ -316,6 +320,10 @@ export type CreateGlobal = = any>( export type UpdateGlobalArgs = any> = { data: T + /** + * Additional database adapter specific options to pass to the query + */ + options?: Record req: PayloadRequest select?: SelectType slug: string @@ -380,6 +388,10 @@ export type DeleteVersions = (args: DeleteVersionsArgs) => Promise export type UpdateVersionArgs = { collection: string locale?: string + /** + * Additional database adapter specific options to pass to the query + */ + options?: Record req: PayloadRequest select?: SelectType versionData: T