To use Payload with MongoDB, install the package @payloadcms/db-mongodb. It will come with everything you need to store your Payload data in MongoDB.
Then from there, pass it to your Payload Config as follows:
Option | Description |
|---|---|
| Tell Mongoose to auto-pluralize any collection names if it encounters any singular words used as collection |
| Customize MongoDB connection options. Payload will connect to your MongoDB database using default options which you can override and extend to include all the options available to mongoose. |
| Customize Mongoose schema options for collections. |
| Set to true to disable hinting to MongoDB to use 'id' as index. This is currently done when counting documents for pagination, as it increases the speed of the count function used in that query. Disabling this optimization might fix some problems with AWS DocumentDB. Defaults to false |
| Customize the directory that migrations are stored. |
| An object with configuration properties used in transactions or |
| Enable language-specific string comparison with customizable options. Available on MongoDB 3.4+. Defaults locale to "en". Example: |
| By default, Payload strips all additional keys from MongoDB data that don't exist in the Payload schema. If you have some data that you want to include to the result but it doesn't exist in Payload, you can set this to |
| Set to |
| Set to |
| Set to |
| Set to |
| Set to |
| Set to |
After Payload is initialized, this adapter exposes all of your Mongoose models and they are available for you to work with directly.
You can access Mongoose models as follows:
payload.db.collections[myCollectionSlug]payload.db.globalspayload.db.versions[myEntitySlug]You can import the compatibilityOptions object to get the recommended settings for other MongoDB implementations. Since these databases aren't officially supported by payload, you may still encounter issues even with these settings (please create an issue or PR if you believe these options should be updated):
We export compatibility options for DocumentDB, Azure Cosmos DB and Firestore. Known limitations:
indexSortableFields to be set to true.