@payloadcms/db-mongodb 3.29.0-canary.7 → 3.29.0-canary.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/updateMany.d.ts +1 -1
- package/dist/updateMany.d.ts.map +1 -1
- package/dist/updateMany.js +24 -3
- package/dist/updateMany.js.map +1 -1
- package/package.json +3 -3
package/dist/updateMany.d.ts
CHANGED
package/dist/updateMany.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateMany.d.ts","sourceRoot":"","sources":["../src/updateMany.ts"],"names":[],"mappings":"AAEA,OAAO,EAA2B,KAAK,UAAU,EAAE,MAAM,SAAS,CAAA;AAYlE,eAAO,MAAM,UAAU,EAAE,UAiGxB,CAAA"}
|
package/dist/updateMany.js
CHANGED
|
@@ -1,14 +1,31 @@
|
|
|
1
|
+
import { flattenWhereToOperators } from 'payload';
|
|
1
2
|
import { buildQuery } from './queries/buildQuery.js';
|
|
3
|
+
import { buildSortParam } from './queries/buildSortParam.js';
|
|
2
4
|
import { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js';
|
|
3
5
|
import { getCollection } from './utilities/getEntity.js';
|
|
4
6
|
import { getSession } from './utilities/getSession.js';
|
|
5
7
|
import { handleError } from './utilities/handleError.js';
|
|
6
8
|
import { transform } from './utilities/transform.js';
|
|
7
|
-
export const updateMany = async function updateMany({ collection: collectionSlug, data, limit, locale, options: optionsArgs = {}, req, returning, select, where }) {
|
|
9
|
+
export const updateMany = async function updateMany({ collection: collectionSlug, data, limit, locale, options: optionsArgs = {}, req, returning, select, sort: sortArg, where }) {
|
|
10
|
+
let hasNearConstraint = false;
|
|
11
|
+
if (where) {
|
|
12
|
+
const constraints = flattenWhereToOperators(where);
|
|
13
|
+
hasNearConstraint = constraints.some((prop)=>Object.keys(prop).some((key)=>key === 'near'));
|
|
14
|
+
}
|
|
8
15
|
const { collectionConfig, Model } = getCollection({
|
|
9
16
|
adapter: this,
|
|
10
17
|
collectionSlug
|
|
11
18
|
});
|
|
19
|
+
let sort;
|
|
20
|
+
if (!hasNearConstraint) {
|
|
21
|
+
sort = buildSortParam({
|
|
22
|
+
config: this.payload.config,
|
|
23
|
+
fields: collectionConfig.flattenedFields,
|
|
24
|
+
locale,
|
|
25
|
+
sort: sortArg || collectionConfig.defaultSort,
|
|
26
|
+
timestamps: true
|
|
27
|
+
});
|
|
28
|
+
}
|
|
12
29
|
const options = {
|
|
13
30
|
...optionsArgs,
|
|
14
31
|
lean: true,
|
|
@@ -40,7 +57,8 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
40
57
|
limit,
|
|
41
58
|
projection: {
|
|
42
59
|
_id: 1
|
|
43
|
-
}
|
|
60
|
+
},
|
|
61
|
+
sort
|
|
44
62
|
});
|
|
45
63
|
if (documentsToUpdate.length === 0) {
|
|
46
64
|
return null;
|
|
@@ -62,7 +80,10 @@ export const updateMany = async function updateMany({ collection: collectionSlug
|
|
|
62
80
|
if (returning === false) {
|
|
63
81
|
return null;
|
|
64
82
|
}
|
|
65
|
-
const result = await Model.find(query, {},
|
|
83
|
+
const result = await Model.find(query, {}, {
|
|
84
|
+
...options,
|
|
85
|
+
sort
|
|
86
|
+
});
|
|
66
87
|
transform({
|
|
67
88
|
adapter: this,
|
|
68
89
|
data: result,
|
package/dist/updateMany.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\nimport type
|
|
1
|
+
{"version":3,"sources":["../src/updateMany.ts"],"sourcesContent":["import type { MongooseUpdateQueryOptions } from 'mongoose'\n\nimport { flattenWhereToOperators, type UpdateMany } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { handleError } from './utilities/handleError.js'\nimport { transform } from './utilities/transform.js'\n\nexport const updateMany: UpdateMany = async function updateMany(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n data,\n limit,\n locale,\n options: optionsArgs = {},\n req,\n returning,\n select,\n sort: sortArg,\n where,\n },\n) {\n let hasNearConstraint = false\n\n if (where) {\n const constraints = flattenWhereToOperators(where)\n hasNearConstraint = constraints.some((prop) => Object.keys(prop).some((key) => key === 'near'))\n }\n\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\n\n let sort: Record<string, unknown> | undefined\n if (!hasNearConstraint) {\n sort = buildSortParam({\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n timestamps: true,\n })\n }\n\n const options: MongooseUpdateQueryOptions = {\n ...optionsArgs,\n lean: true,\n new: true,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n }),\n session: await getSession(this, req),\n }\n\n let query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n transform({ adapter: this, data, fields: collectionConfig.fields, operation: 'write' })\n\n try {\n if (typeof limit === 'number' && limit > 0) {\n const documentsToUpdate = await Model.find(\n query,\n {},\n { ...options, limit, projection: { _id: 1 }, sort },\n )\n if (documentsToUpdate.length === 0) {\n return null\n }\n\n query = { _id: { $in: documentsToUpdate.map((doc) => doc._id) } }\n }\n\n await Model.updateMany(query, data, options)\n } catch (error) {\n handleError({ collection: collectionSlug, error, req })\n }\n\n if (returning === false) {\n return null\n }\n\n const result = await Model.find(\n query,\n {},\n {\n ...options,\n sort,\n },\n )\n\n transform({\n adapter: this,\n data: result,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","handleError","transform","updateMany","collection","collectionSlug","data","limit","locale","options","optionsArgs","req","returning","select","sort","sortArg","where","hasNearConstraint","constraints","some","prop","Object","keys","key","collectionConfig","Model","adapter","config","payload","fields","flattenedFields","defaultSort","timestamps","lean","new","projection","session","query","operation","documentsToUpdate","find","_id","length","$in","map","doc","error","result"],"mappings":"AAEA,SAASA,uBAAuB,QAAyB,UAAS;AAIlE,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,WAAW,QAAQ,6BAA4B;AACxD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,aAAyB,eAAeA,WAEnD,EACEC,YAAYC,cAAc,EAC1BC,IAAI,EACJC,KAAK,EACLC,MAAM,EACNC,SAASC,cAAc,CAAC,CAAC,EACzBC,GAAG,EACHC,SAAS,EACTC,MAAM,EACNC,MAAMC,OAAO,EACbC,KAAK,EACN;IAED,IAAIC,oBAAoB;IAExB,IAAID,OAAO;QACT,MAAME,cAAcvB,wBAAwBqB;QAC5CC,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAG1B,cAAc;QAAE2B,SAAS,IAAI;QAAErB;IAAe;IAElF,IAAIS;IACJ,IAAI,CAACG,mBAAmB;QACtBH,OAAOjB,eAAe;YACpB8B,QAAQ,IAAI,CAACC,OAAO,CAACD,MAAM;YAC3BE,QAAQL,iBAAiBM,eAAe;YACxCtB;YACAM,MAAMC,WAAWS,iBAAiBO,WAAW;YAC7CC,YAAY;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 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/db-mongodb",
|
|
3
|
-
"version": "3.29.0-canary.
|
|
3
|
+
"version": "3.29.0-canary.8",
|
|
4
4
|
"description": "The officially supported MongoDB database adapter for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"mongodb": "6.12.0",
|
|
50
50
|
"mongodb-memory-server": "^10",
|
|
51
51
|
"@payloadcms/eslint-config": "3.28.0",
|
|
52
|
-
"payload": "3.29.0-canary.
|
|
52
|
+
"payload": "3.29.0-canary.8"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"payload": "3.29.0-canary.
|
|
55
|
+
"payload": "3.29.0-canary.8"
|
|
56
56
|
},
|
|
57
57
|
"scripts": {
|
|
58
58
|
"build": "pnpm build:types && pnpm build:swc",
|