Skip to content

Commit 4baba91

Browse files
authored
fix(db-mongodb): bump mongoose to 8.22.1 for GHSA-wpg9-53fq-2r8h (#16688)
Identical to #16672, back-ported for 3.x.
1 parent efa4afe commit 4baba91

11 files changed

Lines changed: 170 additions & 121 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@
217217
"husky": "9.0.11",
218218
"lint-staged": "15.2.7",
219219
"minimist": "1.2.8",
220-
"mongoose": "8.15.1",
220+
"mongoose": "8.22.1",
221221
"next": "16.2.3",
222222
"node-gyp": "12.2.0",
223223
"open": "^10.1.0",

packages/db-mongodb/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"lint:fix": "eslint . --fix"
5353
},
5454
"dependencies": {
55-
"mongoose": "8.15.1",
55+
"mongoose": "8.22.1",
5656
"mongoose-paginate-v2": "1.9.4",
5757
"prompts": "2.4.2",
5858
"uuid": "13.0.2"
@@ -61,7 +61,7 @@
6161
"@payloadcms/eslint-config": "workspace:*",
6262
"@types/mongoose-aggregate-paginate-v2": "1.0.12",
6363
"@types/prompts": "^2.4.5",
64-
"mongodb": "6.16.0",
64+
"mongodb": "6.20.0",
6565
"mongodb-memory-server": "10.1.4",
6666
"payload": "workspace:*"
6767
},

packages/db-mongodb/src/deleteOne.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions } from 'mongoose'
1+
import type { QueryOptions } from 'mongoose'
22
import type { DeleteOne } from 'payload'
33

44
import type { MongooseAdapter } from './index.js'
@@ -22,14 +22,14 @@ export const deleteOne: DeleteOne = async function deleteOne(
2222
where,
2323
})
2424

25-
const options: MongooseUpdateQueryOptions = {
25+
const options = {
2626
projection: buildProjectionFromSelect({
2727
adapter: this,
2828
fields: collectionConfig.flattenedFields,
2929
select,
3030
}),
3131
session: await getSession(this, req),
32-
}
32+
} satisfies QueryOptions
3333

3434
if (returning === false) {
3535
await Model.deleteOne(query, options)?.lean()

packages/db-mongodb/src/updateGlobal.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions } from 'mongoose'
1+
import type { QueryOptions } from 'mongoose'
22
import type { UpdateGlobal } from 'payload'
33

44
import type { MongooseAdapter } from './index.js'
@@ -18,26 +18,30 @@ export const updateGlobal: UpdateGlobal = async function updateGlobal(
1818

1919
transform({ adapter: this, data, fields, globalSlug, operation: 'write' })
2020

21-
const options: MongooseUpdateQueryOptions = {
21+
const baseOptions = {
2222
...optionsArgs,
23+
session: await getSession(this, req),
24+
// Timestamps are manually added by the write transform
25+
timestamps: false,
26+
} satisfies QueryOptions
27+
28+
const findOptions: QueryOptions = {
29+
...baseOptions,
2330
lean: true,
2431
new: true,
2532
projection: buildProjectionFromSelect({
2633
adapter: this,
2734
fields: globalConfig.flattenedFields,
2835
select,
2936
}),
30-
session: await getSession(this, req),
31-
// Timestamps are manually added by the write transform
32-
timestamps: false,
3337
}
3438

3539
if (returning === false) {
36-
await Model.updateOne({ globalType: globalSlug }, data, options)
40+
await Model.updateOne({ globalType: globalSlug }, data, baseOptions)
3741
return null
3842
}
3943

40-
const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, options)
44+
const result: any = await Model.findOneAndUpdate({ globalType: globalSlug }, data, findOptions)
4145

4246
transform({ adapter: this, data: result, fields, globalSlug, operation: 'read' })
4347

packages/db-mongodb/src/updateGlobalVersion.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions } from 'mongoose'
1+
import type { QueryOptions } from 'mongoose'
22
import type { JsonObject, UpdateGlobalVersionArgs } from 'payload'
33

44
import { buildVersionGlobalFields } from 'payload'
@@ -40,26 +40,30 @@ export async function updateGlobalVersion<T extends JsonObject = JsonObject>(
4040

4141
transform({ adapter: this, data: versionData, fields, operation: 'write' })
4242

43-
const options: MongooseUpdateQueryOptions = {
43+
const baseOptions = {
4444
...optionsArgs,
45+
session: await getSession(this, req),
46+
// Timestamps are manually added by the write transform
47+
timestamps: false,
48+
} satisfies QueryOptions
49+
50+
const findOptions: QueryOptions = {
51+
...baseOptions,
4552
lean: true,
4653
new: true,
4754
projection: buildProjectionFromSelect({
4855
adapter: this,
4956
fields: flattenedFields,
5057
select,
5158
}),
52-
session: await getSession(this, req),
53-
// Timestamps are manually added by the write transform
54-
timestamps: false,
5559
}
5660

5761
if (returning === false) {
58-
await Model.updateOne(query, versionData, options)
62+
await Model.updateOne(query, versionData, baseOptions)
5963
return null
6064
}
6165

62-
const doc = await Model.findOneAndUpdate(query, versionData, options)
66+
const doc = await Model.findOneAndUpdate(query, versionData, findOptions)
6367

6468
if (!doc) {
6569
return null

packages/db-mongodb/src/updateJobs.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'
1+
import type { QueryOptions, UpdateQuery } from 'mongoose'
22
import type { Job, UpdateJobs, Where } from 'payload'
33

44
import type { MongooseAdapter } from './index.js'
@@ -80,33 +80,37 @@ export const updateJobs: UpdateJobs = async function updateMany(
8080
updateData = updateOps
8181
}
8282

83-
const options: MongooseUpdateQueryOptions = {
84-
lean: true,
85-
new: true,
83+
const baseOptions = {
8684
session: await getSession(this, req),
8785
// Timestamps are manually added by the write transform
8886
timestamps: false,
87+
} satisfies QueryOptions
88+
89+
const findOptions: QueryOptions = {
90+
...baseOptions,
91+
lean: true,
92+
new: true,
8993
}
9094

9195
let result: Job[] = []
9296

9397
try {
9498
if (id) {
9599
if (returning === false) {
96-
await Model.updateOne(query, updateData, options)
100+
await Model.updateOne(query, updateData, baseOptions)
97101
transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'read' })
98102

99103
return null
100104
} else {
101-
const doc = await Model.findOneAndUpdate(query, updateData, options)
105+
const doc = await Model.findOneAndUpdate(query, updateData, findOptions)
102106
result = doc ? [doc] : []
103107
}
104108
} else {
105109
if (typeof limit === 'number' && limit > 0) {
106110
const documentsToUpdate = await Model.find(
107111
query,
108112
{},
109-
{ ...options, limit, projection: { _id: 1 }, sort },
113+
{ ...findOptions, limit, projection: { _id: 1 }, sort },
110114
)
111115
if (documentsToUpdate.length === 0) {
112116
return null
@@ -115,20 +119,13 @@ export const updateJobs: UpdateJobs = async function updateMany(
115119
query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }
116120
}
117121

118-
await Model.updateMany(query, updateData, options)
122+
await Model.updateMany(query, updateData, baseOptions)
119123

120124
if (returning === false) {
121125
return null
122126
}
123127

124-
result = await Model.find(
125-
query,
126-
{},
127-
{
128-
...options,
129-
sort,
130-
},
131-
)
128+
result = await Model.find(query, {}, { ...findOptions, sort })
132129
}
133130
} catch (error) {
134131
handleError({ collection: collectionConfig.slug, error, req })

packages/db-mongodb/src/updateMany.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'
1+
import type { QueryOptions, UpdateQuery } from 'mongoose'
22

33
import { flattenWhereToOperators, type UpdateMany } from 'payload'
44

@@ -91,26 +91,30 @@ export const updateMany: UpdateMany = async function updateMany(
9191
data = updateOps
9292
}
9393

94-
const options: MongooseUpdateQueryOptions = {
94+
const baseOptions = {
9595
...optionsArgs,
96+
session: await getSession(this, req),
97+
// Timestamps are manually added by the write transform
98+
timestamps: false,
99+
} satisfies QueryOptions
100+
101+
const findOptions: QueryOptions = {
102+
...baseOptions,
96103
lean: true,
97104
new: true,
98105
projection: buildProjectionFromSelect({
99106
adapter: this,
100107
fields: collectionConfig.flattenedFields,
101108
select,
102109
}),
103-
session: await getSession(this, req),
104-
// Timestamps are manually added by the write transform
105-
timestamps: false,
106110
}
107111

108112
try {
109113
if (typeof limit === 'number' && limit > 0) {
110114
const documentsToUpdate = await Model.find(
111115
query,
112116
{},
113-
{ ...options, limit, projection: { _id: 1 }, sort },
117+
{ ...findOptions, limit, projection: { _id: 1 }, sort },
114118
)
115119
if (documentsToUpdate.length === 0) {
116120
return null
@@ -119,7 +123,7 @@ export const updateMany: UpdateMany = async function updateMany(
119123
query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }
120124
}
121125

122-
await Model.updateMany(query, data, options)
126+
await Model.updateMany(query, data, baseOptions)
123127
} catch (error) {
124128
handleError({ collection: collectionSlug, error, req })
125129
}
@@ -132,7 +136,7 @@ export const updateMany: UpdateMany = async function updateMany(
132136
query,
133137
{},
134138
{
135-
...options,
139+
...findOptions,
136140
sort,
137141
},
138142
)

packages/db-mongodb/src/updateOne.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions, UpdateQuery } from 'mongoose'
1+
import type { QueryOptions, UpdateQuery } from 'mongoose'
22
import type { UpdateOne } from 'payload'
33

44
import type { MongooseAdapter } from './index.js'
@@ -75,27 +75,31 @@ export const updateOne: UpdateOne = async function updateOne(
7575
updateData = updateOps
7676
}
7777

78-
const options: MongooseUpdateQueryOptions = {
78+
const baseOptions = {
7979
...optionsArgs,
80+
session: await getSession(this, req),
81+
// Timestamps are manually added by the write transform
82+
timestamps: false,
83+
} satisfies QueryOptions
84+
85+
const findOptions: QueryOptions = {
86+
...baseOptions,
8087
lean: true,
8188
new: true,
8289
projection: buildProjectionFromSelect({
8390
adapter: this,
8491
fields: collectionConfig.flattenedFields,
8592
select,
8693
}),
87-
session: await getSession(this, req),
88-
// Timestamps are manually added by the write transform
89-
timestamps: false,
9094
}
9195

9296
try {
9397
if (returning === false) {
94-
await Model.updateOne(query, updateData, options)
98+
await Model.updateOne(query, updateData, baseOptions)
9599
transform({ adapter: this, data, fields, operation: 'read' })
96100
return null
97101
} else {
98-
result = await Model.findOneAndUpdate(query, updateData, options)
102+
result = await Model.findOneAndUpdate(query, updateData, findOptions)
99103
}
100104
} catch (error) {
101105
handleError({ collection: collectionSlug, error, req })

packages/db-mongodb/src/updateVersion.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { MongooseUpdateQueryOptions } from 'mongoose'
1+
import type { QueryOptions } from 'mongoose'
22

33
import { buildVersionCollectionFields, type UpdateVersion } from 'payload'
44

@@ -44,26 +44,30 @@ export const updateVersion: UpdateVersion = async function updateVersion(
4444

4545
transform({ adapter: this, data: versionData, fields, operation: 'write' })
4646

47-
const options: MongooseUpdateQueryOptions = {
47+
const baseOptions = {
4848
...optionsArgs,
49+
session: await getSession(this, req),
50+
// Timestamps are manually added by the write transform
51+
timestamps: false,
52+
} satisfies QueryOptions
53+
54+
const findOptions: QueryOptions = {
55+
...baseOptions,
4956
lean: true,
5057
new: true,
5158
projection: buildProjectionFromSelect({
5259
adapter: this,
5360
fields: flattenedFields,
5461
select,
5562
}),
56-
session: await getSession(this, req),
57-
// Timestamps are manually added by the write transform
58-
timestamps: false,
5963
}
6064

6165
if (returning === false) {
62-
await Model.updateOne(query, versionData, options)
66+
await Model.updateOne(query, versionData, baseOptions)
6367
return null
6468
}
6569

66-
const doc = await Model.findOneAndUpdate(query, versionData, options)
70+
const doc = await Model.findOneAndUpdate(query, versionData, findOptions)
6771

6872
if (!doc) {
6973
return null

0 commit comments

Comments
 (0)