Plagin to get a collection from database #1841
Replies: 2 comments 2 replies
-
@agolovan this makes perfect sense to me. You are needing to await a response from your external database before building the Payload config. Sounds like we need to build the plugin configs asynchronously. Here's an entry-point into this: https://github.com/payloadcms/payload/blob/96002dbda5e28565e9bbc3927dfd985798859e36/src/config/build.ts This sounds entirely possible but I'll do some digging here. |
Beta Was this translation helpful? Give feedback.
-
How could I get a response from external database when using plagin as it is running at web browser? At this time it is under a web application that could write/read to MonboDB, could we use same API? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
We are planning to store collections into database and allow non coders from separate UI to modify this collection. Each of this collections actually a document. This is how it looks:

I want to create a plugin that allow to get collection from database and merge with collections that are defined in typescript, This is how plugin looks with hardcoded external collection:
const myCollections: Array = [
{
slug: 'MilaCollection',
admin: {
useAsTitle: 'Eddie',
},
access: {},
fields: [
{
name: 'Eddie',
type: 'text',
localized: true,
maxLength: 99999,
minLength: 1,
index: true,
unique: true,
},
{
name: 'Larisa',
type: 'text',
localized: true,
maxLength: 99999,
minLength: 1,
index: true,
unique: true,
},
],
},
];
const addCollectionsFromDatabase: Plugin = (incomingConfig: Config): Config => {
// Spread the existing config
const config: Config = {
...incomingConfig,
collections: [
...incomingConfig.collections, ...myCollections
]
};
return config;
};
export default addCollectionsFromDatabase;
However, in place of myCollections, I need to use async/await and get data from database. I am getting CollectionConfig[] type from database, how I could use that in this plugin?
Beta Was this translation helpful? Give feedback.
All reactions