diff --git a/docs/configuration/overview.mdx b/docs/configuration/overview.mdx index 0c7db48dcaf..04d37f9a636 100644 --- a/docs/configuration/overview.mdx +++ b/docs/configuration/overview.mdx @@ -19,31 +19,32 @@ Payload is a _config-based_, code-first CMS and application framework. The Paylo ## Options -| Option | Description | -| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -| `serverURL` | A string used to define the absolute URL of your app including the protocol, for example `https://example.com`. No paths allowed, only protocol, domain and (optionally) port | -| `collections` | An array of all Collections that Payload will manage. To read more about how to define your collection configs, [click here](/docs/configuration/collections). | -| `cors` | Either a whitelist array of URLS to allow CORS requests from, or a wildcard string (`'*'`) to accept incoming requests from any domain. | -| `globals` | An array of all Globals that Payload will manage. For more on Globals and their configs, [click here](/docs/configuration/globals). | -| `admin` | Base Payload admin configuration. Specify custom components, control metadata, set the Admin user collection, and [more](/docs/admin/overview#admin-options). | -| `localization` | Opt-in and control how Payload handles the translation of your content into multiple locales. [More](/docs/configuration/localization) | -| `graphQL` | Manage GraphQL-specific functionality here. Define your own queries and mutations, manage query complexity limits, and [more](/docs/graphql/overview#graphql-options). | -| `cookiePrefix` | A string that will be prefixed to all cookies that Payload sets. | -| `csrf` | A whitelist array of URLs to allow Payload cookies to be accepted from as a form of CSRF protection. [More](/docs/authentication/overview#csrf-protection) | -| `defaultDepth` | If a user does not specify `depth` while requesting a resource, this depth will be used. [More](/docs/getting-started/concepts#depth) | -| `maxDepth` | The maximum allowed depth to be permitted application-wide. This setting helps prevent against malicious queries. Defaults to `10`. | -| `indexSortableFields` | Automatically index all sortable top-level fields in the database to improve sort performance and add database compatibility for Azure Cosmos and similar. | -| `upload` | Base Payload upload configuration. [More](/docs/upload/overview#payload-wide-upload-options). | -| `routes` | Control the routing structure that Payload binds itself to. Specify `admin`, `api`, `graphQL`, and `graphQLPlayground`. | -| `email` | Base email settings to allow Payload to generate email such as Forgot Password requests and other requirements. [More](/docs/email/overview#configuration) | -| `express` | Express-specific middleware options such as compression and JSON parsing. [More](/docs/configuration/express) | -| `debug` | Enable to expose more detailed error information. | -| `telemetry` | Disable Payload telemetry by passing `false`. [More](/docs/configuration/overview#telemetry) | -| `rateLimit` | Control IP-based rate limiting for all Payload resources. Used to prevent DDoS attacks and [more](/docs/production/preventing-abuse#rate-limiting-requests). | -| `hooks` | Tap into Payload-wide hooks. [More](/docs/hooks/overview) | -| `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | -| `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | -| `custom` | Extension point for adding custom data (e.g. for plugins) | +| Option | Description | +| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | +| `serverURL` | A string used to define the absolute URL of your app including the protocol, for example `https://example.com`. No paths allowed, only protocol, domain and (optionally) port | +| `collections` | An array of all Collections that Payload will manage. To read more about how to define your collection configs, [click here](/docs/configuration/collections). | +| `cors` | Either a whitelist array of URLS to allow CORS requests from, or a wildcard string (`'*'`) to accept incoming requests from any domain. | +| `globals` | An array of all Globals that Payload will manage. For more on Globals and their configs, [click here](/docs/configuration/globals). | +| `admin` | Base Payload admin configuration. Specify custom components, control metadata, set the Admin user collection, and [more](/docs/admin/overview#admin-options). | +| `localization` | Opt-in and control how Payload handles the translation of your content into multiple locales. [More](/docs/configuration/localization) | +| `graphQL` | Manage GraphQL-specific functionality here. Define your own queries and mutations, manage query complexity limits, and [more](/docs/graphql/overview#graphql-options). | +| `cookiePrefix` | A string that will be prefixed to all cookies that Payload sets. | +| `csrf` | A whitelist array of URLs to allow Payload cookies to be accepted from as a form of CSRF protection. [More](/docs/authentication/overview#csrf-protection) | +| `defaultDepth` | If a user does not specify `depth` while requesting a resource, this depth will be used. [More](/docs/getting-started/concepts#depth) | +| `maxDepth` | The maximum allowed depth to be permitted application-wide. This setting helps prevent against malicious queries. Defaults to `10`. | +| `indexSortableFields` | Automatically index all sortable top-level fields in the database to improve sort performance and add database compatibility for Azure Cosmos and similar. | +| `upload` | Base Payload upload configuration. [More](/docs/upload/overview#payload-wide-upload-options). | +| `routes` | Control the routing structure that Payload binds itself to. Specify `admin`, `api`, `graphQL`, and `graphQLPlayground`. | +| `email` | Base email settings to allow Payload to generate email such as Forgot Password requests and other requirements. [More](/docs/email/overview#configuration) | +| `express` | Express-specific middleware options such as compression and JSON parsing. [More](/docs/configuration/express) | +| `debug` | Enable to expose more detailed error information. | +| `telemetry` | Disable Payload telemetry by passing `false`. [More](/docs/configuration/overview#telemetry) | +| `rateLimit` | Control IP-based rate limiting for all Payload resources. Used to prevent DDoS attacks and [more](/docs/production/preventing-abuse#rate-limiting-requests). | +| `hooks` | Tap into Payload-wide hooks. [More](/docs/hooks/overview) | +| `plugins` | An array of Payload plugins. [More](/docs/plugins/overview) | +| `endpoints` | An array of custom API endpoints added to the Payload router. [More](/docs/rest-api/overview#custom-endpoints) | +| `custom` | Extension point for adding custom data (e.g. for plugins) | +| `pluralizeSlugs` | By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database (e.g. if your slug is `post`, it will be saved as `posts`in the database.) | #### Simple example diff --git a/src/collections/initLocal.ts b/src/collections/initLocal.ts index cc65fb66f71..29721f26f64 100644 --- a/src/collections/initLocal.ts +++ b/src/collections/initLocal.ts @@ -56,7 +56,7 @@ export default function initCollectionsLocal(ctx: Payload): void { ctx.collections[formattedCollection.slug] = { - Model: mongoose.model(formattedCollection.slug, schema) as CollectionModel, + Model: mongoose.model(formattedCollection.slug, schema, ctx.config.pluralizeSlugs === false ? formattedCollection.slug : undefined) as CollectionModel, config: formattedCollection, }; diff --git a/src/config/schema.ts b/src/config/schema.ts index 33a3ccef057..e988f869660 100644 --- a/src/config/schema.ts +++ b/src/config/schema.ts @@ -164,4 +164,5 @@ export default joi.object({ onInit: joi.func(), debug: joi.boolean(), custom: joi.object().pattern(joi.string(), joi.any()), + pluralizeSlugs: joi.boolean().optional().default(true), }); diff --git a/src/config/types.ts b/src/config/types.ts index 0720666988c..9e3cbb7e6e9 100644 --- a/src/config/types.ts +++ b/src/config/types.ts @@ -530,6 +530,12 @@ export type Config = { onInit?: (payload: Payload) => Promise | void; /** Extension point to add your custom data. */ custom?: Record; + /** + * By default, mongoose will pluralize all singular slugs so that they are saved as plural in the database. + * + * @default true + */ + pluralizeSlugs?: boolean; }; export type SanitizedConfig = Omit<