@payloadcms/db-mongodb 3.80.0-internal.cee0ccf → 3.81.0-canary.0

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.
@@ -1 +1 @@
1
- {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAUpC,eAAO,MAAM,KAAK,EAAE,KAgDnB,CAAA"}
1
+ {"version":3,"file":"count.d.ts","sourceRoot":"","sources":["../src/count.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,SAAS,CAAA;AAUpC,eAAO,MAAM,KAAK,EAAE,KA2DnB,CAAA"}
package/dist/count.js CHANGED
@@ -24,6 +24,14 @@ export const count = async function count({ collection: collectionSlug, locale,
24
24
  const options = {
25
25
  session: await getSession(this, req)
26
26
  };
27
+ if (this.collation) {
28
+ const localizationConfig = this.payload.config.localization;
29
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
30
+ options.collation = {
31
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
32
+ ...this.collation
33
+ };
34
+ }
27
35
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
28
36
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
29
37
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
package/dist/count.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getCollection","getSession","count","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,QAAe,eAAeA,MAEzC,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAAEU,SAAS,IAAI;QAAEN;IAAe;IAElF,IAAIO,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAcd,wBAAwBS;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMnB,WAAW;QAC7BW,SAAS,IAAI;QACbN;QACAe,QAAQX,iBAAiBY,eAAe;QACxCf;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMc,oBAAoBV,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMvB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,CAACe,qBAAqBN,OAAOC,IAAI,CAACE,OAAOI,MAAM,KAAK,KAAK,IAAI,CAACG,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BF,QAAQG,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIP,mBAAmB;QACrBO,SAAS,MAAMnB,MAAMoB,sBAAsB,CAAC;YAAEL,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLI,SAAS,MAAMnB,MAAMqB,cAAc,CAACZ,OAAOK;IAC7C;IAEA,OAAO;QACLQ,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/count.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { Count } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const count: Count = async function count(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["flattenWhereToOperators","buildQuery","getCollection","getSession","count","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","flattenedFields","useEstimatedCount","length","options","session","collation","localizationConfig","payload","config","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAM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BAAsB,CAAC;YAAEX,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLU,SAAS,MAAMzB,MAAM2B,cAAc,CAAClB,OAAOK;IAC7C;IAEA,OAAO;QACLc,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA+CjC,CAAA"}
1
+ {"version":3,"file":"countGlobalVersions.d.ts","sourceRoot":"","sources":["../src/countGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAA;AAUlD,eAAO,MAAM,mBAAmB,EAAE,mBA0DjC,CAAA"}
@@ -24,6 +24,14 @@ export const countGlobalVersions = async function countGlobalVersions({ global:
24
24
  const options = {
25
25
  session: await getSession(this, req)
26
26
  };
27
+ if (this.collation) {
28
+ const localizationConfig = this.payload.config.localization;
29
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
30
+ options.collation = {
31
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
32
+ ...this.collation
33
+ };
34
+ }
27
35
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
28
36
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
29
37
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getGlobal","getSession","countGlobalVersions","global","globalSlug","locale","req","where","globalConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGT,UAAU;QAAEU,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IAEtF,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,yBAAyB,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,cAAc;QACpEH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,CAACiB,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACG,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BF,QAAQG,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIP,mBAAmB;QACrBO,SAAS,MAAMrB,MAAMsB,sBAAsB,CAAC;YAAEL,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLI,SAAS,MAAMrB,MAAMuB,cAAc,CAACb,OAAOM;IAC7C;IAEA,OAAO;QACLQ,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countGlobalVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountGlobalVersions } from 'payload'\n\nimport { buildVersionGlobalFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countGlobalVersions: CountGlobalVersions = async function countGlobalVersions(\n this: MongooseAdapter,\n { global: globalSlug, locale, req, where = {} },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","getGlobal","getSession","countGlobalVersions","global","globalSlug","locale","req","where","globalConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAI3E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,sBAA2C,eAAeA,oBAErE,EAAEC,QAAQC,UAAU,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAE/C,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGT,UAAU;QAAEU,SAAS,IAAI;QAAEN;QAAYO,UAAU;IAAK;IAEtF,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,yBAAyB,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,cAAc;QACpEH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACqB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOF,uBAAuB,YAAYA,oBAAoBE,iBAAkB;QAEnFL,QAAQE,SAAS,GAAG;YAClBtB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACH,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,eAAO,MAAM,aAAa,EAAE,aAmD3B,CAAA"}
1
+ {"version":3,"file":"countVersions.d.ts","sourceRoot":"","sources":["../src/countVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAU5C,eAAO,MAAM,aAAa,EAAE,aA8D3B,CAAA"}
@@ -24,6 +24,14 @@ export const countVersions = async function countVersions({ collection: collecti
24
24
  const options = {
25
25
  session: await getSession(this, req)
26
26
  };
27
+ if (this.collation) {
28
+ const localizationConfig = this.payload.config.localization;
29
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
30
+ options.collation = {
31
+ locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
32
+ ...this.collation
33
+ };
34
+ }
27
35
  if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {
28
36
  // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding
29
37
  // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getCollection","getSession","countVersions","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAChDU,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IAEA,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,6BAA6B,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,kBAAkB;QAC5EH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,CAACiB,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACG,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BF,QAAQG,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIP,mBAAmB;QACrBO,SAAS,MAAMrB,MAAMsB,sBAAsB,CAAC;YAAEL,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLI,SAAS,MAAMrB,MAAMuB,cAAc,CAACb,OAAOM;IAC7C;IAEA,OAAO;QACLQ,WAAWH;IACb;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/countVersions.ts"],"sourcesContent":["import type { CountOptions } from 'mongodb'\nimport type { CountVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\n\nexport const countVersions: CountVersions = async function countVersions(\n this: MongooseAdapter,\n { collection: collectionSlug, locale, req, where = {} },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\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 query = await buildQuery({\n adapter: this,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig, true),\n locale,\n where,\n })\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n\n const options: CountOptions = {\n session: await getSession(this, req),\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n options.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n options.hint = {\n _id: 1,\n }\n }\n\n let result: number\n if (useEstimatedCount) {\n result = await Model.estimatedDocumentCount({ session: options.session })\n } else {\n result = await Model.countDocuments(query, options)\n }\n\n return {\n totalDocs: result,\n }\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","getCollection","getSession","countVersions","collection","collectionSlug","locale","req","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","query","fields","payload","config","useEstimatedCount","length","options","session","collation","localizationConfig","localization","defaultLocale","disableIndexHints","hint","_id","result","estimatedDocumentCount","countDocuments","totalDocs"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AAEtD,OAAO,MAAMC,gBAA+B,eAAeA,cAEzD,EAAEC,YAAYC,cAAc,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,CAAC,CAAC,EAAE;IAEvD,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGT,cAAc;QAChDU,SAAS,IAAI;QACbN;QACAO,UAAU;IACZ;IAEA,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcf,wBAAwBS;QAC5CK,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,QAAQ,MAAMpB,WAAW;QAC7BW,SAAS,IAAI;QACbU,QAAQvB,6BAA6B,IAAI,CAACwB,OAAO,CAACC,MAAM,EAAEd,kBAAkB;QAC5EH;QACAE;IACF;IAEA,4HAA4H;IAC5H,MAAMgB,oBAAoBX,qBAAqB,CAACO,SAASH,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK;IAEvF,MAAMC,UAAwB;QAC5BC,SAAS,MAAMzB,WAAW,IAAI,EAAEK;IAClC;IAEA,IAAI,IAAI,CAACqB,SAAS,EAAE;QAClB,MAAMC,qBAAqB,IAAI,CAACP,OAAO,CAACC,MAAM,CAACO,YAAY;QAC3D,MAAMC,gBACJ,AAAC,OAAOF,uBAAuB,YAAYA,oBAAoBE,iBAAkB;QAEnFL,QAAQE,SAAS,GAAG;YAClBtB,QAAQA,UAAUA,WAAW,SAASA,WAAW,MAAMA,SAASyB;YAChE,GAAG,IAAI,CAACH,SAAS;QACnB;IACF;IAEA,IAAI,CAACJ,qBAAqBP,OAAOC,IAAI,CAACE,OAAOK,MAAM,KAAK,KAAK,IAAI,CAACO,iBAAiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,QAAQO,IAAI,GAAG;YACbC,KAAK;QACP;IACF;IAEA,IAAIC;IACJ,IAAIX,mBAAmB;QACrBW,SAAS,MAAMzB,MAAM0B,sBAAsB,CAAC;YAAET,SAASD,QAAQC,OAAO;QAAC;IACzE,OAAO;QACLQ,SAAS,MAAMzB,MAAM2B,cAAc,CAACjB,OAAOM;IAC7C;IAEA,OAAO;QACLY,WAAWH;IACb;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAgBnC,eAAO,MAAM,IAAI,EAAE,IAgKlB,CAAA"}
1
+ {"version":3,"file":"find.d.ts","sourceRoot":"","sources":["../src/find.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,SAAS,CAAA;AAgBnC,eAAO,MAAM,IAAI,EAAE,IAiLlB,CAAA"}
package/dist/find.js CHANGED
@@ -61,7 +61,8 @@ export const find = async function find({ collection: collectionSlug, draftsEnab
61
61
  });
62
62
  }
63
63
  if (this.collation) {
64
- const defaultLocale = 'en';
64
+ const localizationConfig = this.payload.config.localization;
65
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
65
66
  paginationOptions.collation = {
66
67
  locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
67
68
  ...this.collation
@@ -74,12 +75,24 @@ export const find = async function find({ collection: collectionSlug, draftsEnab
74
75
  // the correct indexed field
75
76
  paginationOptions.useCustomCountFn = ()=>{
76
77
  return Promise.resolve(Model.countDocuments(query, {
78
+ collation: paginationOptions.collation,
77
79
  hint: {
78
80
  _id: 1
79
81
  },
80
82
  session
81
83
  }));
82
84
  };
85
+ } else if (!useEstimatedCount && this.collation) {
86
+ // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks
87
+ // session context in transactions (mongoose 8.x). Provide custom count function that passes
88
+ // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240
89
+ // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.
90
+ paginationOptions.useCustomCountFn = ()=>{
91
+ return Promise.resolve(Model.countDocuments(query, {
92
+ collation: paginationOptions.collation,
93
+ session
94
+ }));
95
+ };
83
96
  }
84
97
  if (limit >= 0) {
85
98
  paginationOptions.limit = limit;
package/dist/find.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n draftsEnabled,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 sortAggregation: PipelineStage[] = []\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: collectionConfig.timestamps || false,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options: {\n session,\n },\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection: paginationOptions.projection,\n query,\n })\n\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","find","collection","collectionSlug","draftsEnabled","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","sortAggregation","config","payload","fields","flattenedFields","defaultSort","timestamps","query","session","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,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AAM,GAAG,GAAG;QAC3Cc,SAAS,MAAMxD,kBAAkB;YAC/BwB,SAAS,IAAI;YACbuB,WAAWJ,kBAAkBI,SAAS;YACtCW,iBAAiBD;YACjB7C,OAAO+B,kBAAkB/B,KAAK;YAC9BW;YACAT,MAAM6B,kBAAkB7B,IAAI;YAC5BC,YAAY4B,kBAAkB5B,UAAU;YACxCC,YAAY2B,kBAAkB3B,UAAU;YACxCuB;YACAC,SAASG,kBAAkBG,OAAO,EAAEN,WAAWmB;YAC/CxC,MAAMwB,kBAAkBxB,IAAI;YAC5Ba;YACAS,mBAAmBE,kBAAkBF,iBAAiB;QACxD;IACF,OAAO;QACLe,SAAS,MAAMjC,MAAMqC,QAAQ,CAACrB,OAAOI;IACvC;IAEA,IAAI,CAAC,IAAI,CAACkB,mBAAmB,EAAE;QAC7B,MAAMxD,aAAa;YACjBmB,SAAS,IAAI;YACbf;YACAqD,MAAMN,OAAOM,IAAI;YACjBnD;YACAE;QACF;IACF;IAEAP,UAAU;QACRkB,SAAS,IAAI;QACbuC,MAAMP,OAAOM,IAAI;QACjB3B,QAAQb,iBAAiBa,MAAM;QAC/B6B,WAAW;IACb;IAEA,OAAOR;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/find.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage } from 'mongoose'\nimport type { Find } from 'payload'\n\nimport { flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const find: Find = async function find(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n draftsEnabled,\n joins = {},\n limit = 0,\n locale,\n page,\n pagination,\n projection,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({ adapter: this, collectionSlug })\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 sortAggregation: PipelineStage[] = []\n\n let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: collectionConfig.timestamps || false,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n collectionSlug,\n fields: collectionConfig.flattenedFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options: {\n session,\n },\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (select) {\n paginationOptions.projection = buildProjectionFromSelect({\n adapter: this,\n fields: collectionConfig.flattenedFields,\n select,\n })\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n draftsEnabled,\n joins,\n locale,\n projection: paginationOptions.projection,\n query,\n })\n\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(query, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: collectionConfig.fields,\n operation: 'read',\n })\n\n return result\n}\n"],"names":["flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","find","collection","collectionSlug","draftsEnabled","joins","limit","locale","page","pagination","projection","req","select","sort","sortArg","where","collectionConfig","Model","adapter","hasNearConstraint","constraints","some","prop","Object","keys","key","sortAggregation","config","payload","fields","flattenedFields","defaultSort","timestamps","query","session","useEstimatedCount","length","paginationOptions","lean","leanWithId","options","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation"],"mappings":"AAGA,SAASA,uBAAuB,QAAQ,UAAS;AAIjD,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,OAAa,eAAeA,KAEvC,EACEC,YAAYC,cAAc,EAC1BC,aAAa,EACbC,QAAQ,CAAC,CAAC,EACVC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGpB,cAAc;QAAEqB,SAAS,IAAI;QAAEf;IAAe;IAElF,IAAIgB,oBAAoB;IAExB,IAAIJ,OAAO;QACT,MAAMK,cAAc7B,wBAAwBwB;QAC5CI,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,MAAMC,kBAAmC,EAAE;IAE3C,IAAIb;IACJ,IAAI,CAACM,mBAAmB;QACtBN,OAAOpB,eAAe;YACpByB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IAEA,IAAI,CAAC,IAAI,CAACoB,mBAAmB,EAAE;QAC7B,MAAM1D,aAAa;YACjBmB,SAAS,IAAI;YACbf;YACAuD,MAAMN,OAAOM,IAAI;YACjBrD;YACAE;QACF;IACF;IAEAP,UAAU;QACRkB,SAAS,IAAI;QACbyC,MAAMP,OAAOM,IAAI;QACjB7B,QAAQb,iBAAiBa,MAAM;QAC/B+B,WAAW;IACb;IAEA,OAAOR;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAajD,eAAO,MAAM,kBAAkB,EAAE,kBAgHhC,CAAA"}
1
+ {"version":3,"file":"findGlobalVersions.d.ts","sourceRoot":"","sources":["../src/findGlobalVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAajD,eAAO,MAAM,kBAAkB,EAAE,kBAiIhC,CAAA"}
@@ -60,7 +60,8 @@ export const findGlobalVersions = async function findGlobalVersions({ global: gl
60
60
  useEstimatedCount
61
61
  };
62
62
  if (this.collation) {
63
- const defaultLocale = 'en';
63
+ const localizationConfig = this.payload.config.localization;
64
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
64
65
  paginationOptions.collation = {
65
66
  locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
66
67
  ...this.collation
@@ -73,12 +74,24 @@ export const findGlobalVersions = async function findGlobalVersions({ global: gl
73
74
  // the correct indexed field
74
75
  paginationOptions.useCustomCountFn = ()=>{
75
76
  return Promise.resolve(Model.countDocuments(query, {
77
+ collation: paginationOptions.collation,
76
78
  hint: {
77
79
  _id: 1
78
80
  },
79
81
  session
80
82
  }));
81
83
  };
84
+ } else if (!useEstimatedCount && this.collation) {
85
+ // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks
86
+ // session context in transactions (mongoose 8.x). Provide custom count function that passes
87
+ // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240
88
+ // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.
89
+ paginationOptions.useCustomCountFn = ()=>{
90
+ return Promise.resolve(Model.countDocuments(query, {
91
+ collation: paginationOptions.collation,
92
+ session
93
+ }));
94
+ };
82
95
  }
83
96
  if (limit >= 0) {
84
97
  paginationOptions.limit = limit;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload'\n\nimport { APIError, buildVersionGlobalFields, flattenWhereToOperators } 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 { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global: globalSlug,\n limit = 0,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const versionFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: versionFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n // Calculate skip from page for cases where pagination is disabled but offset is still needed\n const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig),\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getGlobal","getSession","transform","findGlobalVersions","global","globalSlug","limit","locale","page","pagination","req","select","sort","sortArg","where","globalConfig","Model","adapter","versions","versionFields","payload","config","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","session","skip","undefined","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","data","docs","operation"],"mappings":"AAGA,SAAmBA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAIrF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,QAAQC,UAAU,EAClBC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEZ;QAAYa,UAAU;IAAK;IAEtF,MAAMC,gBAAgBxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEN,cAAc;IAElF,IAAIO,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAc3B,wBAAwBkB;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOd,eAAe;YACpBmB,SAAS,IAAI;YACbI,QAAQ,IAAI,CAACD,OAAO,CAACC,MAAM;YAC3BQ,QAAQV;YACRZ;YACAK,MAAMC,WAAW;YACjBiB,YAAY;QACd;IACF;IAEA,MAAMC,QAAQ,MAAMlC,WAAW;QAC7BoB,SAAS,IAAI;QACbY,QAAQV;QACRZ;QACAO;IACF;IAEA,MAAMkB,UAA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OO;IAE3CpC,UAAU;QACRe,SAAS,IAAI;QACboC,MAAMF,OAAOG,IAAI;QACjBzB,QAAQlC,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEN;QACtDwC,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findGlobalVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindGlobalVersions } from 'payload'\n\nimport { APIError, buildVersionGlobalFields, flattenWhereToOperators } 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 { getGlobal } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { transform } from './utilities/transform.js'\n\nexport const findGlobalVersions: FindGlobalVersions = async function findGlobalVersions(\n this: MongooseAdapter,\n {\n global: globalSlug,\n limit = 0,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { globalConfig, Model } = getGlobal({ adapter: this, globalSlug, versions: true })\n\n const versionFields = buildVersionGlobalFields(this.payload.config, globalConfig, true)\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: versionFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const query = await buildQuery({\n adapter: this,\n fields: versionFields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n // Calculate skip from page for cases where pagination is disabled but offset is still needed\n const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({ adapter: this, fields: versionFields, select }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionGlobalFields(this.payload.config, globalConfig),\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildVersionGlobalFields","flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getGlobal","getSession","transform","findGlobalVersions","global","globalSlug","limit","locale","page","pagination","req","select","sort","sortArg","where","globalConfig","Model","adapter","versions","versionFields","payload","config","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","timestamps","query","session","skip","undefined","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","data","docs","operation"],"mappings":"AAGA,SAAmBA,wBAAwB,EAAEC,uBAAuB,QAAQ,UAAS;AAIrF,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,SAAS,QAAQ,2BAA0B;AACpD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,qBAAyC,eAAeA,mBAEnE,EACEC,QAAQC,UAAU,EAClBC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,YAAY,EAAEC,KAAK,EAAE,GAAGhB,UAAU;QAAEiB,SAAS,IAAI;QAAEZ;QAAYa,UAAU;IAAK;IAEtF,MAAMC,gBAAgBxB,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEN,cAAc;IAElF,IAAIO,oBAAoB;IAExB,IAAIR,OAAO;QACT,MAAMS,cAAc3B,wBAAwBkB;QAC5CQ,oBAAoBC,YAAYC,IAAI,CAAC,CAACC,OAASC,OAAOC,IAAI,CAACF,MAAMD,IAAI,CAAC,CAACI,MAAQA,QAAQ;IACzF;IAEA,IAAIhB;IACJ,IAAI,CAACU,mBAAmB;QACtBV,OAAOd,eAAe;YACp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,MAAMkC,cAAc,CAACnB,OAAO;gBAC1BW,WAAWJ,kBAAkBI,SAAS;gBACtCS,MAAM;oBAAEC,KAAK;gBAAE;gBACfpB;YACF;QAEJ;IACF,OAAO,IAAI,CAACI,qBAAqB,IAAI,CAACM,SAAS,EAAE;QAC/C,0FAA0F;QAC1F,4FAA4F;QAC5F,kGAAkG;QAClG,kFAAkF;QAClFJ,kBAAkBS,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpBjC,MAAMkC,cAAc,CAACnB,OAAO;gBAC1BW,WAAWJ,kBAAkBI,SAAS;gBACtCV;YACF;QAEJ;IACF;IAEA,IAAI1B,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QAErEgC,kBAAkBH,OAAO,CAAE7B,KAAK,GAAGA;QAEnC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM4C,SAAS,MAAMrC,MAAMsC,QAAQ,CAACvB,OAAOO;IAE3CpC,UAAU;QACRe,SAAS,IAAI;QACbsC,MAAMF,OAAOG,IAAI;QACjB3B,QAAQlC,yBAAyB,IAAI,CAACyB,OAAO,CAACC,MAAM,EAAEN;QACtD0C,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAa3C,eAAO,MAAM,YAAY,EAAE,YAwH1B,CAAA"}
1
+ {"version":3,"file":"findVersions.d.ts","sourceRoot":"","sources":["../src/findVersions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAa3C,eAAO,MAAM,YAAY,EAAE,YAyI1B,CAAA"}
@@ -60,7 +60,8 @@ export const findVersions = async function findVersions({ collection: collection
60
60
  useEstimatedCount
61
61
  };
62
62
  if (this.collation) {
63
- const defaultLocale = 'en';
63
+ const localizationConfig = this.payload.config.localization;
64
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
64
65
  paginationOptions.collation = {
65
66
  locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
66
67
  ...this.collation
@@ -73,12 +74,24 @@ export const findVersions = async function findVersions({ collection: collection
73
74
  // the correct indexed field
74
75
  paginationOptions.useCustomCountFn = ()=>{
75
76
  return Promise.resolve(Model.countDocuments(query, {
77
+ collation: paginationOptions.collation,
76
78
  hint: {
77
79
  _id: 1
78
80
  },
79
81
  session
80
82
  }));
81
83
  };
84
+ } else if (!useEstimatedCount && this.collation) {
85
+ // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks
86
+ // session context in transactions (mongoose 8.x). Provide custom count function that passes
87
+ // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240
88
+ // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.
89
+ paginationOptions.useCustomCountFn = ()=>{
90
+ return Promise.resolve(Model.countDocuments(query, {
91
+ collation: paginationOptions.collation,
92
+ session
93
+ }));
94
+ };
82
95
  }
83
96
  if (limit >= 0) {
84
97
  paginationOptions.limit = limit;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } 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 { transform } from './utilities/transform.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n limit = 0,\n locale,\n page,\n pagination,\n req = {},\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n // Calculate skip from page for cases where pagination is disabled but offset is still needed\n const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n hint: { _id: 1 },\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","transform","findVersions","collection","collectionSlug","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","config","payload","fields","flattenedFields","timestamps","query","session","skip","undefined","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","data","docs","operation"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,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,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,YAAYC,cAAc,EAC1BC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAC,EACRC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGhB,cAAc;QAChDiB,SAAS,IAAI;QACbZ;QACAa,UAAU;IACZ;IAEA,IAAIC,oBAAoB;IAExB,IAAIL,OAAO;QACT,MAAMM,cAAcxB,wBAAwBk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AiB,KAAK,MAAM;QAC5F,mHAAmH;QACnH,qHAAqH;QACrH,mHAAmH;QACnH,4BAA4B;QAC5BN,kBAAkBO,gBAAgB,GAAG;YACnC,OAAOC,QAAQC,OAAO,CACpB/B,MAAMgC,cAAc,CAACjB,OAAO;gBAC1BkB,MAAM;oBAAEC,KAAK;gBAAE;gBACflB;YACF;QAEJ;IACF;IAEA,IAAI1B,SAAS,GAAG;QACdgC,kBAAkBhC,KAAK,GAAGA;QAC1B,qEAAqE;QAErEgC,kBAAkBH,OAAO,CAAE7B,KAAK,GAAGA;QAEnC,mCAAmC;QACnC,IAAIA,UAAU,GAAG;YACfgC,kBAAkB7B,UAAU,GAAG;QACjC;IACF;IAEA,MAAM0C,SAAS,MAAMnC,MAAMoC,QAAQ,CAACrB,OAAOO;IAE3CpC,UAAU;QACRe,SAAS,IAAI;QACboC,MAAMF,OAAOG,IAAI;QACjB1B,QAAQjC,6BAA6B,IAAI,CAACgC,OAAO,CAACD,MAAM,EAAEX;QAC1DwC,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/findVersions.ts"],"sourcesContent":["import type { PaginateOptions, QueryOptions } from 'mongoose'\nimport type { FindVersions } from 'payload'\n\nimport { buildVersionCollectionFields, flattenWhereToOperators } 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 { transform } from './utilities/transform.js'\n\nexport const findVersions: FindVersions = async function findVersions(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n limit = 0,\n locale,\n page,\n pagination,\n req = {},\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\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 let sort\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields: collectionConfig.flattenedFields,\n locale,\n sort: sortArg || '-updatedAt',\n timestamps: true,\n })\n }\n\n const fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const query = await buildQuery({\n adapter: this,\n fields,\n locale,\n where,\n })\n\n const session = await getSession(this, req)\n // Calculate skip from page for cases where pagination is disabled but offset is still needed\n const skip = typeof page === 'number' && page > 1 ? (page - 1) * (limit || 0) : undefined\n const options: QueryOptions = {\n limit,\n session,\n skip,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount = hasNearConstraint || !query || Object.keys(query).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n limit,\n options,\n page,\n pagination,\n projection: buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n }),\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (!useEstimatedCount && Object.keys(query).length === 0 && this.disableIndexHints !== true) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(query, {\n collation: paginationOptions.collation,\n session,\n }),\n )\n }\n }\n\n if (limit >= 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n\n // Disable pagination if limit is 0\n if (limit === 0) {\n paginationOptions.pagination = false\n }\n }\n\n const result = await Model.paginate(query, paginationOptions)\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n return result\n}\n"],"names":["buildVersionCollectionFields","flattenWhereToOperators","buildQuery","buildSortParam","buildProjectionFromSelect","getCollection","getSession","transform","findVersions","collection","collectionSlug","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","config","payload","fields","flattenedFields","timestamps","query","session","skip","undefined","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","projection","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","paginate","data","docs","operation"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,uBAAuB,QAAQ,UAAS;AAI/E,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,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,eAA6B,eAAeA,aAEvD,EACEC,YAAYC,cAAc,EAC1BC,QAAQ,CAAC,EACTC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,MAAM,CAAC,CAAC,EACRC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AACgC,OAAO,CAACD,MAAM,EAAEX;QAC1D0C,WAAW;IACb;IAEA,OAAOJ;AACT,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACd,QAAQ,EACR,OAAO,EAER,MAAM,SAAS,CAAA;AAMhB,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAoED,eAAO,MAAM,kBAAkB,qFAS5B,sBAAsB,KACrB;IACE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,GACD,SA4bH,CAAA"}
1
+ {"version":3,"file":"sanitizeQueryValue.d.ts","sourceRoot":"","sources":["../../src/queries/sanitizeQueryValue.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,cAAc,EACd,QAAQ,EACR,OAAO,EAER,MAAM,SAAS,CAAA;AAMhB,KAAK,sBAAsB,GAAG;IAC5B,KAAK,EAAE,cAAc,CAAA;IACrB,WAAW,EAAE,OAAO,CAAA;IACpB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,QAAQ,CAAA;IAClB,iBAAiB,EAAE,OAAO,CAAA;IAC1B,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,OAAO,CAAA;IAChB,GAAG,EAAE,GAAG,CAAA;CACT,CAAA;AAoED,eAAO,MAAM,kBAAkB,qFAS5B,sBAAsB,KACrB;IACE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,GAAG,CAAC,EAAE,OAAO,CAAA;CACd,GACD,SAycH,CAAA"}
@@ -423,12 +423,28 @@ export const sanitizeQueryValue = ({ field, hasCustomID, locale, operator, paren
423
423
  }
424
424
  if (path !== '_id' || path === '_id' && hasCustomID && field.type === 'text') {
425
425
  if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {
426
- if ('hasMany' in field && field.hasMany && [
426
+ if ('hasMany' in field && field.hasMany && field.type === 'select') {
427
+ // For hasMany select, "contains" means the array includes this exact value
428
+ if (typeof formattedValue === 'string') {
429
+ return {
430
+ rawQuery: {
431
+ [path]: formattedValue
432
+ }
433
+ };
434
+ } else if (Array.isArray(formattedValue)) {
435
+ return {
436
+ rawQuery: {
437
+ $or: formattedValue.map((val)=>({
438
+ [path]: val
439
+ }))
440
+ }
441
+ };
442
+ }
443
+ } else if ('hasMany' in field && field.hasMany && [
427
444
  'number',
428
- 'select',
429
445
  'text'
430
446
  ].includes(field.type)) {
431
- // For array fields, we need to use $elemMatch to search within array elements
447
+ // For hasMany text/number, "contains" means substring matching within array elements
432
448
  if (typeof formattedValue === 'string') {
433
449
  // Search for documents where any array element contains this string
434
450
  const escapedValue = escapeRegExp(formattedValue);
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n Operator,\n Payload,\n RelationshipField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated, escapeRegExp } from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue: unknown, path: string, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n payload,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n payload: Payload\n segments: string[]\n}): FlattenedField | undefined => {\n if ('blocks' in field || 'blockReferences' in field) {\n const _field: FlattenedBlocksField = field as FlattenedBlocksField\n for (const _block of _field.blockReferences ?? _field.blocks) {\n const block: FlattenedBlock | undefined =\n typeof _block === 'string' ? payload.blocks[_block] : _block\n if (block) {\n const field = getFieldFromSegments({ field: block, payload, segments })\n if (field) {\n return field\n }\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, payload, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs):\n | {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n }\n | undefined => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, payload, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n if (Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce<unknown[]>((formattedValues, inVal) => {\n if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n\n return formattedValues\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\n }, [])\n }\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number' && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n let localizedPath = path\n\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n payload.config.localization &&\n locale\n ) {\n localizedPath = `${path}.${locale}`\n }\n\n return {\n rawQuery: {\n $or: [\n {\n [localizedPath]: {\n $eq: {\n // disable auto sort\n /* eslint-disable */\n value: formattedValue.value,\n relationTo: formattedValue.relationTo,\n /* eslint-enable */\n },\n },\n },\n {\n [localizedPath]: {\n $eq: {\n relationTo: formattedValue.relationTo,\n value: formattedValue.value,\n },\n },\n },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo]?.customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo]?.customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n // Handle hasMany relationships with equals operator and array values\n // For array equality checking\n if (\n ['equals', 'not_equals'].includes(operator) &&\n Array.isArray(formattedValue) &&\n 'hasMany' in field &&\n field.hasMany\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo]?.customIDType\n\n // Convert array values to proper types (ObjectId or custom ID type)\n formattedValue = formattedValue.map((v) => {\n if (customIDType === 'number') {\n const parsed = parseFloat(v)\n return Number.isNaN(parsed) ? v : parsed\n }\n if (!Types.ObjectId.isValid(v)) {\n return v\n }\n return new Types.ObjectId(v)\n })\n } else {\n // Polymorphic hasMany - convert array of {relationTo, value} objects\n formattedValue = formattedValue.map((item) => {\n if (typeof item === 'object' && 'value' in item) {\n const relTo = item.relationTo\n const customIDType = payload.collections[relTo]?.customIDType\n if (customIDType === 'number') {\n const parsed = parseFloat(item.value)\n return { relationTo: relTo, value: Number.isNaN(parsed) ? item.value : parsed }\n }\n if (Types.ObjectId.isValid(item.value)) {\n return { relationTo: relTo, value: new Types.ObjectId(item.value) }\n }\n return item\n }\n // Non-polymorphic format - just IDs\n if (Types.ObjectId.isValid(item)) {\n return new Types.ObjectId(item)\n }\n return item\n })\n }\n } else if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo]?.customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo]?.customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n }\n }\n\n if (\n operator === 'all' &&\n Array.isArray(relationTo) &&\n path.endsWith('.value') &&\n Array.isArray(formattedValue)\n ) {\n formattedValue.forEach((v, i) => {\n if (Types.ObjectId.isValid(v)) {\n formattedValue[i] = new Types.ObjectId(v)\n }\n })\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance && !Number.isNaN(Number(maxDistance))) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n\n if (minDistance && !Number.isNaN(Number(minDistance))) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {\n if (\n 'hasMany' in field &&\n field.hasMany &&\n ['number', 'select', 'text'].includes(field.type)\n ) {\n // For array fields, we need to use $elemMatch to search within array elements\n if (typeof formattedValue === 'string') {\n // Search for documents where any array element contains this string\n const escapedValue = escapeRegExp(formattedValue)\n return {\n rawQuery: {\n [path]: {\n $elemMatch: {\n $options: 'i',\n $regex: escapedValue,\n },\n },\n },\n }\n } else if (Array.isArray(formattedValue)) {\n // Search for documents where any array element contains any of the search values\n return {\n rawQuery: {\n $or: formattedValue.map((val) => {\n const escapedValue = escapeRegExp(String(val))\n return {\n [path]: {\n $elemMatch: {\n $options: 'i',\n $regex: escapedValue,\n },\n },\n }\n }),\n },\n }\n }\n } else {\n // Regular (non-hasMany) text field\n formattedValue = {\n $options: 'i',\n $regex: escapeRegExp(formattedValue),\n }\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n let treatEmptyString = !['array', 'blocks', 'checkbox', 'relationship', 'upload'].includes(\n field.type,\n )\n\n if (field.type === 'text' && field.hasMany) {\n treatEmptyString = false\n } else if (field.type === 'number' && field.hasMany) {\n treatEmptyString = false\n } else if (field.type === 'select' && field.hasMany) {\n treatEmptyString = false\n }\n\n // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(formattedValue, path, treatEmptyString)\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["Types","createArrayFromCommaDelineated","escapeRegExp","fieldShouldBeLocalized","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","payload","segments","_field","_block","blockReferences","blocks","block","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","parentIsLocalized","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","localizedPath","config","localization","collections","customIDType","some","toString","hasMany","v","parsed","item","relTo","endsWith","hasCustomIDType","formattedNumber","forEach","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","escapedValue","$elemMatch","$options","$regex","String"],"mappings":"AASA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,EAAEC,YAAY,QAAQ,UAAS;AACtE,SAASC,sBAAsB,QAAQ,iBAAgB;AAavD,MAAMC,mBAAmB,CAACC,gBAAyBC,MAAcC,mBAAmB,IAAI;IACtF,IAAIF,gBAAgB;QAClB,OAAO;YACLG,UAAU;gBACRC,MAAM;oBACJ;wBAAE,CAACH,KAAK,EAAE;4BAAEI,SAAS;wBAAK;oBAAE;oBAC5B;wBAAE,CAACJ,KAAK,EAAE;4BAAEK,KAAK;wBAAK;oBAAE;uBACpBJ,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEK,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF,OAAO;QACL,OAAO;YACLH,UAAU;gBACRI,KAAK;oBACH;wBAAE,CAACN,KAAK,EAAE;4BAAEI,SAAS;wBAAM;oBAAE;oBAC7B;wBAAE,CAACJ,KAAK,EAAE;4BAAEO,KAAK;wBAAK;oBAAE;uBACpBN,mBAAmB;wBAAC;4BAAE,CAACD,KAAK,EAAE;gCAAEO,KAAK;4BAAG;wBAAE;qBAAE,GAAG,EAAE;iBACtD;YACH;QACF;IACF;AACF;AAEA,6HAA6H;AAC7H,MAAMC,uBAAuB,CAAC,EAC5BC,KAAK,EACLC,OAAO,EACPC,QAAQ,EAKT;IACC,IAAI,YAAYF,SAAS,qBAAqBA,OAAO;QACnD,MAAMG,SAA+BH;QACrC,KAAK,MAAMI,U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4BAAC;gCAAE,CAACN,KAAK,EAAE;oCAAEI,SAAS;gCAAM;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEO,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEqB,UAAUG;QAAmBD,KAAK/B;IAAe;AAC5D,EAAC"}
1
+ {"version":3,"sources":["../../src/queries/sanitizeQueryValue.ts"],"sourcesContent":["import type {\n FlattenedBlock,\n FlattenedBlocksField,\n FlattenedField,\n Operator,\n Payload,\n RelationshipField,\n} from 'payload'\n\nimport { Types } from 'mongoose'\nimport { createArrayFromCommaDelineated, escapeRegExp } from 'payload'\nimport { fieldShouldBeLocalized } from 'payload/shared'\n\ntype SanitizeQueryValueArgs = {\n field: FlattenedField\n hasCustomID: boolean\n locale?: string\n operator: Operator\n parentIsLocalized: boolean\n path: string\n payload: Payload\n val: any\n}\n\nconst buildExistsQuery = (formattedValue: unknown, path: string, treatEmptyString = true) => {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [\n { [path]: { $exists: true } },\n { [path]: { $ne: null } },\n ...(treatEmptyString ? [{ [path]: { $ne: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [\n { [path]: { $exists: false } },\n { [path]: { $eq: null } },\n ...(treatEmptyString ? [{ [path]: { $eq: '' } }] : []), // Treat empty string as null / undefined\n ],\n },\n }\n }\n}\n\n// returns nestedField Field object from blocks.nestedField path because getLocalizedPaths splits them only for relationships\nconst getFieldFromSegments = ({\n field,\n payload,\n segments,\n}: {\n field: FlattenedBlock | FlattenedField\n payload: Payload\n segments: string[]\n}): FlattenedField | undefined => {\n if ('blocks' in field || 'blockReferences' in field) {\n const _field: FlattenedBlocksField = field as FlattenedBlocksField\n for (const _block of _field.blockReferences ?? _field.blocks) {\n const block: FlattenedBlock | undefined =\n typeof _block === 'string' ? payload.blocks[_block] : _block\n if (block) {\n const field = getFieldFromSegments({ field: block, payload, segments })\n if (field) {\n return field\n }\n }\n }\n }\n\n if ('fields' in field) {\n for (let i = 0; i < segments.length; i++) {\n const foundField = field.flattenedFields.find((each) => each.name === segments[i])\n\n if (!foundField) {\n break\n }\n\n if (foundField && segments.length - 1 === i) {\n return foundField\n }\n\n segments.shift()\n return getFieldFromSegments({ field: foundField, payload, segments })\n }\n }\n}\n\nexport const sanitizeQueryValue = ({\n field,\n hasCustomID,\n locale,\n operator,\n parentIsLocalized,\n path,\n payload,\n val,\n}: SanitizeQueryValueArgs):\n | {\n operator?: string\n rawQuery?: unknown\n val?: unknown\n }\n | undefined => {\n let formattedValue = val\n let formattedOperator = operator\n\n if (['array', 'blocks', 'group', 'tab'].includes(field.type) && path.includes('.')) {\n const segments = path.split('.')\n segments.shift()\n const foundField = getFieldFromSegments({ field, payload, segments })\n\n if (foundField) {\n field = foundField\n }\n }\n\n // Disregard invalid _ids\n if (path === '_id') {\n if (typeof val === 'string' && val.split(',').length === 1) {\n if (!hasCustomID) {\n const isValid = Types.ObjectId.isValid(val)\n\n if (!isValid) {\n return { operator: formattedOperator, val: undefined }\n } else {\n if (['in', 'not_in'].includes(operator)) {\n formattedValue = createArrayFromCommaDelineated(formattedValue).map(\n (id) => new Types.ObjectId(id),\n )\n } else {\n formattedValue = new Types.ObjectId(val)\n }\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(val)\n\n if (Number.isNaN(parsedNumber)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else if (Array.isArray(val) || (typeof val === 'string' && val.split(',').length > 1)) {\n if (typeof val === 'string') {\n formattedValue = createArrayFromCommaDelineated(val)\n }\n\n if (Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce<unknown[]>((formattedValues, inVal) => {\n if (!hasCustomID) {\n if (Types.ObjectId.isValid(inVal)) {\n formattedValues.push(new Types.ObjectId(inVal))\n\n return formattedValues\n }\n }\n\n if (field.type === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n }\n } else {\n formattedValues.push(inVal)\n }\n\n return formattedValues\n }, [])\n }\n }\n }\n\n // Cast incoming values as proper searchable types\n if (field.type === 'checkbox' && typeof val === 'string') {\n if (val.toLowerCase() === 'true') {\n formattedValue = true\n }\n if (val.toLowerCase() === 'false') {\n formattedValue = false\n }\n }\n\n if (['all', 'in', 'not_in'].includes(operator) && typeof formattedValue === 'string') {\n formattedValue = createArrayFromCommaDelineated(formattedValue)\n\n if (field.type === 'number' && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.map((arrayVal) => parseFloat(arrayVal))\n }\n }\n\n if (field.type === 'number') {\n if (typeof formattedValue === 'string' && operator !== 'exists') {\n formattedValue = Number(val)\n }\n\n if (operator === 'exists') {\n formattedValue = val === 'true' ? true : val === 'false' ? false : Boolean(val)\n return buildExistsQuery(formattedValue, path)\n }\n }\n\n if (field.type === 'date' && typeof val === 'string' && operator !== 'exists') {\n formattedValue = new Date(val)\n if (Number.isNaN(Date.parse(formattedValue))) {\n return undefined\n }\n }\n\n if (['relationship', 'upload'].includes(field.type)) {\n if (val === 'null') {\n formattedValue = null\n }\n\n // Object equality requires the value to be the first key in the object that is being queried.\n if (\n operator === 'equals' &&\n formattedValue &&\n typeof formattedValue === 'object' &&\n formattedValue.value &&\n formattedValue.relationTo\n ) {\n const { value } = formattedValue\n const isValid = Types.ObjectId.isValid(value)\n\n if (isValid) {\n formattedValue.value = new Types.ObjectId(value)\n }\n\n let localizedPath = path\n\n if (\n fieldShouldBeLocalized({ field, parentIsLocalized }) &&\n payload.config.localization &&\n locale\n ) {\n localizedPath = `${path}.${locale}`\n }\n\n return {\n rawQuery: {\n $or: [\n {\n [localizedPath]: {\n $eq: {\n // disable auto sort\n /* eslint-disable */\n value: formattedValue.value,\n relationTo: formattedValue.relationTo,\n /* eslint-enable */\n },\n },\n },\n {\n [localizedPath]: {\n $eq: {\n relationTo: formattedValue.relationTo,\n value: formattedValue.value,\n },\n },\n },\n ],\n },\n }\n }\n\n const relationTo = (field as RelationshipField).relationTo\n\n if (['in', 'not_in'].includes(operator) && Array.isArray(formattedValue)) {\n formattedValue = formattedValue.reduce((formattedValues, inVal) => {\n if (!inVal) {\n return formattedValues\n }\n\n if (typeof relationTo === 'string' && payload.collections[relationTo]?.customIDType) {\n if (payload.collections[relationTo].customIDType === 'number') {\n const parsedNumber = parseFloat(inVal)\n if (!Number.isNaN(parsedNumber)) {\n formattedValues.push(parsedNumber)\n return formattedValues\n }\n }\n\n formattedValues.push(inVal)\n return formattedValues\n }\n\n if (\n Array.isArray(relationTo) &&\n relationTo.some((relationTo) => !!payload.collections[relationTo]?.customIDType)\n ) {\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n } else {\n formattedValues.push(inVal)\n }\n return formattedValues\n }\n\n if (Types.ObjectId.isValid(inVal.toString())) {\n formattedValues.push(new Types.ObjectId(inVal))\n }\n\n return formattedValues\n }, [])\n }\n\n // Handle hasMany relationships with equals operator and array values\n // For array equality checking\n if (\n ['equals', 'not_equals'].includes(operator) &&\n Array.isArray(formattedValue) &&\n 'hasMany' in field &&\n field.hasMany\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo]?.customIDType\n\n // Convert array values to proper types (ObjectId or custom ID type)\n formattedValue = formattedValue.map((v) => {\n if (customIDType === 'number') {\n const parsed = parseFloat(v)\n return Number.isNaN(parsed) ? v : parsed\n }\n if (!Types.ObjectId.isValid(v)) {\n return v\n }\n return new Types.ObjectId(v)\n })\n } else {\n // Polymorphic hasMany - convert array of {relationTo, value} objects\n formattedValue = formattedValue.map((item) => {\n if (typeof item === 'object' && 'value' in item) {\n const relTo = item.relationTo\n const customIDType = payload.collections[relTo]?.customIDType\n if (customIDType === 'number') {\n const parsed = parseFloat(item.value)\n return { relationTo: relTo, value: Number.isNaN(parsed) ? item.value : parsed }\n }\n if (Types.ObjectId.isValid(item.value)) {\n return { relationTo: relTo, value: new Types.ObjectId(item.value) }\n }\n return item\n }\n // Non-polymorphic format - just IDs\n if (Types.ObjectId.isValid(item)) {\n return new Types.ObjectId(item)\n }\n return item\n })\n }\n } else if (\n ['contains', 'equals', 'like', 'not_equals'].includes(operator) &&\n (!Array.isArray(relationTo) || !path.endsWith('.relationTo'))\n ) {\n if (typeof relationTo === 'string') {\n const customIDType = payload.collections[relationTo]?.customIDType\n\n if (customIDType) {\n if (customIDType === 'number') {\n formattedValue = parseFloat(val)\n\n if (Number.isNaN(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n } else {\n const hasCustomIDType = relationTo.some(\n (relationTo) => !!payload.collections[relationTo]?.customIDType,\n )\n\n if (hasCustomIDType) {\n if (typeof val === 'string') {\n const formattedNumber = Number(val)\n formattedValue = [Types.ObjectId.isValid(val) ? new Types.ObjectId(val) : val]\n formattedOperator = operator === 'not_equals' ? 'not_in' : 'in'\n if (!Number.isNaN(formattedNumber)) {\n formattedValue.push(formattedNumber)\n }\n }\n } else {\n if (!Types.ObjectId.isValid(formattedValue)) {\n return { operator: formattedOperator, val: undefined }\n }\n formattedValue = new Types.ObjectId(formattedValue)\n }\n }\n }\n\n if (\n operator === 'all' &&\n Array.isArray(relationTo) &&\n path.endsWith('.value') &&\n Array.isArray(formattedValue)\n ) {\n formattedValue.forEach((v, i) => {\n if (Types.ObjectId.isValid(v)) {\n formattedValue[i] = new Types.ObjectId(v)\n }\n })\n }\n }\n\n // Set up specific formatting necessary by operators\n\n if (operator === 'near') {\n let lng\n let lat\n let maxDistance\n let minDistance\n\n if (Array.isArray(formattedValue)) {\n ;[lng, lat, maxDistance, minDistance] = formattedValue\n }\n\n if (typeof formattedValue === 'string') {\n ;[lng, lat, maxDistance, minDistance] = createArrayFromCommaDelineated(formattedValue)\n }\n\n if (lng == null || lat == null || (maxDistance == null && minDistance == null)) {\n formattedValue = undefined\n } else {\n formattedValue = {\n $geometry: { type: 'Point', coordinates: [parseFloat(lng), parseFloat(lat)] },\n }\n\n if (maxDistance && !Number.isNaN(Number(maxDistance))) {\n formattedValue.$maxDistance = parseFloat(maxDistance)\n }\n\n if (minDistance && !Number.isNaN(Number(minDistance))) {\n formattedValue.$minDistance = parseFloat(minDistance)\n }\n }\n }\n\n if (operator === 'within' || operator === 'intersects') {\n formattedValue = {\n $geometry: formattedValue,\n }\n }\n\n if (path !== '_id' || (path === '_id' && hasCustomID && field.type === 'text')) {\n if (operator === 'contains' && !Types.ObjectId.isValid(formattedValue)) {\n if ('hasMany' in field && field.hasMany && field.type === 'select') {\n // For hasMany select, \"contains\" means the array includes this exact value\n if (typeof formattedValue === 'string') {\n return {\n rawQuery: {\n [path]: formattedValue,\n },\n }\n } else if (Array.isArray(formattedValue)) {\n return {\n rawQuery: {\n $or: formattedValue.map((val) => ({\n [path]: val,\n })),\n },\n }\n }\n } else if ('hasMany' in field && field.hasMany && ['number', 'text'].includes(field.type)) {\n // For hasMany text/number, \"contains\" means substring matching within array elements\n if (typeof formattedValue === 'string') {\n // Search for documents where any array element contains this string\n const escapedValue = escapeRegExp(formattedValue)\n return {\n rawQuery: {\n [path]: {\n $elemMatch: {\n $options: 'i',\n $regex: escapedValue,\n },\n },\n },\n }\n } else if (Array.isArray(formattedValue)) {\n // Search for documents where any array element contains any of the search values\n return {\n rawQuery: {\n $or: formattedValue.map((val) => {\n const escapedValue = escapeRegExp(String(val))\n return {\n [path]: {\n $elemMatch: {\n $options: 'i',\n $regex: escapedValue,\n },\n },\n }\n }),\n },\n }\n }\n } else {\n // Regular (non-hasMany) text field\n formattedValue = {\n $options: 'i',\n $regex: escapeRegExp(formattedValue),\n }\n }\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n let treatEmptyString = !['array', 'blocks', 'checkbox', 'relationship', 'upload'].includes(\n field.type,\n )\n\n if (field.type === 'text' && field.hasMany) {\n treatEmptyString = false\n } else if (field.type === 'number' && field.hasMany) {\n treatEmptyString = false\n } else if (field.type === 'select' && field.hasMany) {\n treatEmptyString = false\n }\n\n // _id can't be empty string, will error Cast to ObjectId failed for value \"\"\n return buildExistsQuery(formattedValue, path, treatEmptyString)\n }\n }\n\n if (\n (path === '_id' || path === 'parent') &&\n operator === 'like' &&\n formattedValue.length === 24 &&\n !hasCustomID\n ) {\n formattedOperator = 'equals'\n }\n\n if (operator === 'exists') {\n formattedValue = formattedValue === 'true' || formattedValue === true\n\n // Clearable fields\n if (['relationship', 'select', 'upload'].includes(field.type)) {\n if (formattedValue) {\n return {\n rawQuery: {\n $and: [{ [path]: { $exists: true } }, { [path]: { $ne: null } }],\n },\n }\n } else {\n return {\n rawQuery: {\n $or: [{ [path]: { $exists: false } }, { [path]: { $eq: null } }],\n },\n }\n }\n }\n }\n\n return { operator: formattedOperator, val: formattedValue }\n}\n"],"names":["Types","createArrayFromCommaDelineated","escapeRegExp","fieldShouldBeLocalized","buildExistsQuery","formattedValue","path","treatEmptyString","rawQuery","$and","$exists","$ne","$or","$eq","getFieldFromSegments","field","payload","segments","_field","_block","blockReferences","blocks","block","i","length","foundField","flattenedFields","find","each","name","shift","sanitizeQueryValue","hasCustomID","locale","operator","parentIsLocalized","val","formattedOperator","includes","type","split","isValid","ObjectId","undefined","map","id","parsedNumber","parseFloat","Number","isNaN","Array","isArray","reduce","formattedValues","inVal","push","toLowerCase","arrayVal","Boolean","Date","parse","value","relationTo","localizedPath","config","localization","collections","customIDType","some","toString","hasMany","v","parsed","item","relTo","endsWith","hasCustomIDType","formattedNumber","forEach","lng","lat","maxDistance","minDistance","$geometry","coordinates","$maxDistance","$minDistance","escapedValue","$elemMatch","$options","$regex","String"],"mappings":"AASA,SAASA,KAAK,QAAQ,WAAU;AAChC,SAASC,8BAA8B,EAAEC,YAAY,QAAQ,UAAS;AACtE,SAASC,sBAAsB,QAAQ,iBAAgB;AAavD,MAAMC,mB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AS;gCAAM;4BAAE;4BAAG;gCAAE,CAACJ,KAAK,EAAE;oCAAEO,KAAK;gCAAK;4BAAE;yBAAE;oBAClE;gBACF;YACF;QACF;IACF;IAEA,OAAO;QAAEqB,UAAUG;QAAmBD,KAAK/B;IAAe;AAC5D,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAgB1C,eAAO,MAAM,WAAW,EAAE,WA2KzB,CAAA"}
1
+ {"version":3,"file":"queryDrafts.d.ts","sourceRoot":"","sources":["../src/queryDrafts.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAgB1C,eAAO,MAAM,WAAW,EAAE,WA6LzB,CAAA"}
@@ -67,7 +67,8 @@ export const queryDrafts = async function queryDrafts({ collection: collectionSl
67
67
  useEstimatedCount
68
68
  };
69
69
  if (this.collation) {
70
- const defaultLocale = 'en';
70
+ const localizationConfig = this.payload.config.localization;
71
+ const defaultLocale = typeof localizationConfig === 'object' && localizationConfig?.defaultLocale || 'en';
71
72
  paginationOptions.collation = {
72
73
  locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,
73
74
  ...this.collation
@@ -80,9 +81,22 @@ export const queryDrafts = async function queryDrafts({ collection: collectionSl
80
81
  // the correct indexed field
81
82
  paginationOptions.useCustomCountFn = ()=>{
82
83
  return Promise.resolve(Model.countDocuments(versionQuery, {
84
+ collation: paginationOptions.collation,
83
85
  hint: {
84
86
  _id: 1
85
- }
87
+ },
88
+ session
89
+ }));
90
+ };
91
+ } else if (!useEstimatedCount && this.collation) {
92
+ // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks
93
+ // session context in transactions (mongoose 8.x). Provide custom count function that passes
94
+ // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240
95
+ // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.
96
+ paginationOptions.useCustomCountFn = ()=>{
97
+ return Promise.resolve(Model.countDocuments(versionQuery, {
98
+ collation: paginationOptions.collation,
99
+ session
86
100
  }));
87
101
  };
88
102
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint\n let sort\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 fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const defaultLocale = 'en'\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n hint: { _id: 1 },\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,YAAYC,cAAc,EAC1BC,KAAK,EACLC,K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,OAAO;QACLc,SAAS,MAAMrC,MAAM0C,QAAQ,CAACvB,cAAcM;IAC9C;IAEA,IAAI,CAAC,IAAI,CAACkB,mBAAmB,EAAE;QAC7B,MAAM3D,aAAa;YACjBiB,SAAS,IAAI;YACbb;YACAwD,MAAMP,OAAOO,IAAI;YACjBvD;YACAE;YACAW,UAAU;QACZ;IACF;IAEAjB,UAAU;QACRgB,SAAS,IAAI;QACb4C,MAAMR,OAAOO,IAAI;QACjBlC,QAAQpC,6BAA6B,IAAI,CAACqC,OAAO,CAACC,MAAM,EAAEb;QAC1D+C,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIV,OAAOO,IAAI,CAACpB,MAAM,EAAEuB,IAAK;QAC3C,MAAMC,KAAKX,OAAOO,IAAI,CAACG,EAAE,CAACE,MAAM;QAChCZ,OAAOO,IAAI,CAACG,EAAE,GAAGV,OAAOO,IAAI,CAACG,EAAE,CAACG,OAAO,IAAI,CAAC;QAC5Cb,OAAOO,IAAI,CAACG,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOX;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/queryDrafts.ts"],"sourcesContent":["import type { PaginateOptions, PipelineStage, QueryOptions } from 'mongoose'\nimport type { QueryDrafts } from 'payload'\n\nimport { buildVersionCollectionFields, combineQueries, flattenWhereToOperators } from 'payload'\n\nimport type { MongooseAdapter } from './index.js'\n\nimport { buildQuery } from './queries/buildQuery.js'\nimport { buildSortParam } from './queries/buildSortParam.js'\nimport { aggregatePaginate } from './utilities/aggregatePaginate.js'\nimport { buildJoinAggregation } from './utilities/buildJoinAggregation.js'\nimport { buildProjectionFromSelect } from './utilities/buildProjectionFromSelect.js'\nimport { getCollection } from './utilities/getEntity.js'\nimport { getSession } from './utilities/getSession.js'\nimport { resolveJoins } from './utilities/resolveJoins.js'\nimport { transform } from './utilities/transform.js'\n\nexport const queryDrafts: QueryDrafts = async function queryDrafts(\n this: MongooseAdapter,\n {\n collection: collectionSlug,\n joins,\n limit,\n locale,\n page,\n pagination,\n req,\n select,\n sort: sortArg,\n where = {},\n },\n) {\n const { collectionConfig, Model } = getCollection({\n adapter: this,\n collectionSlug,\n versions: true,\n })\n\n let hasNearConstraint\n let sort\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 fields = buildVersionCollectionFields(this.payload.config, collectionConfig, true)\n\n const sortAggregation: PipelineStage[] = []\n if (!hasNearConstraint) {\n sort = buildSortParam({\n adapter: this,\n config: this.payload.config,\n fields,\n locale,\n sort: sortArg || collectionConfig.defaultSort,\n sortAggregation,\n timestamps: true,\n versions: true,\n })\n }\n\n const combinedWhere = combineQueries({ latest: { equals: true } }, where)\n\n const versionQuery = await buildQuery({\n adapter: this,\n fields,\n locale,\n where: combinedWhere,\n })\n\n const projection = buildProjectionFromSelect({\n adapter: this,\n fields,\n select,\n })\n\n const session = await getSession(this, req)\n const options: QueryOptions = {\n session,\n }\n\n // useEstimatedCount is faster, but not accurate, as it ignores any filters. It is thus set to true if there are no filters.\n const useEstimatedCount =\n hasNearConstraint || !versionQuery || Object.keys(versionQuery).length === 0\n const paginationOptions: PaginateOptions = {\n lean: true,\n leanWithId: true,\n options,\n page,\n pagination,\n projection,\n sort,\n useEstimatedCount,\n }\n\n if (this.collation) {\n const localizationConfig = this.payload.config.localization\n const defaultLocale =\n (typeof localizationConfig === 'object' && localizationConfig?.defaultLocale) || 'en'\n\n paginationOptions.collation = {\n locale: locale && locale !== 'all' && locale !== '*' ? locale : defaultLocale,\n ...this.collation,\n }\n }\n\n if (\n !useEstimatedCount &&\n Object.keys(versionQuery).length === 0 &&\n this.disableIndexHints !== true\n ) {\n // Improve the performance of the countDocuments query which is used if useEstimatedCount is set to false by adding\n // a hint. By default, if no hint is provided, MongoDB does not use an indexed field to count the returned documents,\n // which makes queries very slow. This only happens when no query (filter) is provided. If one is provided, it uses\n // the correct indexed field\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n hint: { _id: 1 },\n session,\n }),\n )\n }\n } else if (!useEstimatedCount && this.collation) {\n // Workaround for mongoose-paginate-v2 bug: chaining .collation() on countDocuments breaks\n // session context in transactions (mongoose 8.x). Provide custom count function that passes\n // collation as an option instead. See: https://github.com/aravindnc/mongoose-paginate-v2/pull/240\n // TODO: Remove this workaround once mongoose-paginate-v2 is updated with the fix.\n paginationOptions.useCustomCountFn = () => {\n return Promise.resolve(\n Model.countDocuments(versionQuery, {\n collation: paginationOptions.collation,\n session,\n }),\n )\n }\n }\n\n if (limit && limit > 0) {\n paginationOptions.limit = limit\n // limit must also be set here, it's ignored when pagination is false\n\n paginationOptions.options!.limit = limit\n }\n\n let result\n\n const aggregate = await buildJoinAggregation({\n adapter: this,\n collection: collectionSlug,\n collectionConfig,\n joins,\n locale,\n projection,\n query: versionQuery,\n versions: true,\n })\n\n // build join aggregation\n if (aggregate || sortAggregation.length > 0) {\n result = await aggregatePaginate({\n adapter: this,\n collation: paginationOptions.collation,\n joinAggregation: aggregate,\n limit: paginationOptions.limit,\n Model,\n page: paginationOptions.page,\n pagination: paginationOptions.pagination,\n projection: paginationOptions.projection,\n query: versionQuery,\n session: paginationOptions.options?.session ?? undefined,\n sort: paginationOptions.sort as object,\n sortAggregation,\n useEstimatedCount: paginationOptions.useEstimatedCount,\n })\n } else {\n result = await Model.paginate(versionQuery, paginationOptions)\n }\n\n if (!this.useJoinAggregations) {\n await resolveJoins({\n adapter: this,\n collectionSlug,\n docs: result.docs as Record<string, unknown>[],\n joins,\n locale,\n versions: true,\n })\n }\n\n transform({\n adapter: this,\n data: result.docs,\n fields: buildVersionCollectionFields(this.payload.config, collectionConfig),\n operation: 'read',\n })\n\n for (let i = 0; i < result.docs.length; i++) {\n const id = result.docs[i].parent\n result.docs[i] = result.docs[i].version ?? {}\n result.docs[i].id = id\n }\n\n return result\n}\n"],"names":["buildVersionCollectionFields","combineQueries","flattenWhereToOperators","buildQuery","buildSortParam","aggregatePaginate","buildJoinAggregation","buildProjectionFromSelect","getCollection","getSession","resolveJoins","transform","queryDrafts","collection","collectionSlug","joins","limit","locale","page","pagination","req","select","sort","sortArg","where","collectionConfig","Model","adapter","versions","hasNearConstraint","constraints","some","prop","Object","keys","key","fields","payload","config","sortAggregation","defaultSort","timestamps","combinedWhere","latest","equals","versionQuery","projection","session","options","useEstimatedCount","length","paginationOptions","lean","leanWithId","collation","localizationConfig","localization","defaultLocale","disableIndexHints","useCustomCountFn","Promise","resolve","countDocuments","hint","_id","result","aggregate","query","joinAggregation","undefined","paginate","useJoinAggregations","docs","data","operation","i","id","parent","version"],"mappings":"AAGA,SAASA,4BAA4B,EAAEC,cAAc,EAAEC,uBAAuB,QAAQ,UAAS;AAI/F,SAASC,UAAU,QAAQ,0BAAyB;AACpD,SAASC,cAAc,QAAQ,8BAA6B;AAC5D,SAASC,iBAAiB,QAAQ,mCAAkC;AACpE,SAASC,oBAAoB,QAAQ,sCAAqC;AAC1E,SAASC,yBAAyB,QAAQ,2CAA0C;AACpF,SAASC,aAAa,QAAQ,2BAA0B;AACxD,SAASC,UAAU,QAAQ,4BAA2B;AACtD,SAASC,YAAY,QAAQ,8BAA6B;AAC1D,SAASC,SAAS,QAAQ,2BAA0B;AAEpD,OAAO,MAAMC,cAA2B,eAAeA,YAErD,EACEC,YAAYC,cAAc,EAC1BC,KAAK,EACLC,KAAK,EACLC,MAAM,EACNC,IAAI,EACJC,UAAU,EACVC,GAAG,EACHC,MAAM,EACNC,MAAMC,OAAO,EACbC,QAAQ,CAAC,CAAC,EACX;IAED,MAAM,EAAEC,gBAAgB,EAAEC,KAAK,EAAE,GAAGlB,cAAc;QAChDmB,SAAS,IAAI;QACbb;QACAc,UAAU;IACZ;IAEA,IAAIC;IACJ,IAAIP;IAEJ,IAAIE,OAAO;QACT,MAAMM,cAAc5B,wBAAwBsB;QAC5CK,oBAAoBC,YAAYC,IAAI,C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;YAC/C/C,MAAM6B,kBAAkB7B,IAAI;YAC5BiB;YACAU,mBAAmBE,kBAAkBF,iBAAiB;QACxD;IACF,OAAO;QACLgB,SAAS,MAAMvC,MAAM4C,QAAQ,CAACzB,cAAcM;IAC9C;IAEA,IAAI,CAAC,IAAI,CAACoB,mBAAmB,EAAE;QAC7B,MAAM7D,aAAa;YACjBiB,SAAS,IAAI;YACbb;YACA0D,MAAMP,OAAOO,IAAI;YACjBzD;YACAE;YACAW,UAAU;QACZ;IACF;IAEAjB,UAAU;QACRgB,SAAS,IAAI;QACb8C,MAAMR,OAAOO,IAAI;QACjBpC,QAAQpC,6BAA6B,IAAI,CAACqC,OAAO,CAACC,MAAM,EAAEb;QAC1DiD,WAAW;IACb;IAEA,IAAK,IAAIC,IAAI,GAAGA,IAAIV,OAAOO,IAAI,CAACtB,MAAM,EAAEyB,IAAK;QAC3C,MAAMC,KAAKX,OAAOO,IAAI,CAACG,EAAE,CAACE,MAAM;QAChCZ,OAAOO,IAAI,CAACG,EAAE,GAAGV,OAAOO,IAAI,CAACG,EAAE,CAACG,OAAO,IAAI,CAAC;QAC5Cb,OAAOO,IAAI,CAACG,EAAE,CAACC,EAAE,GAAGA;IACtB;IAEA,OAAOX;AACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/db-mongodb",
3
- "version": "3.80.0-internal.cee0ccf",
3
+ "version": "3.81.0-canary.0",
4
4
  "description": "The officially supported MongoDB database adapter for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -55,10 +55,10 @@
55
55
  "mongodb": "6.16.0",
56
56
  "mongodb-memory-server": "10.1.4",
57
57
  "@payloadcms/eslint-config": "3.28.0",
58
- "payload": "3.80.0-internal.cee0ccf"
58
+ "payload": "3.81.0-canary.0"
59
59
  },
60
60
  "peerDependencies": {
61
- "payload": "3.80.0-internal.cee0ccf"
61
+ "payload": "3.81.0-canary.0"
62
62
  },
63
63
  "scripts": {
64
64
  "build": "pnpm build:types && pnpm build:swc",