I want to check if some collections exist on the database, and if not, seed those collections with some pre-existing static files stored locally.
How can I achieve this in Payload v3? Do I have to build into a custom server?
payload.config.ts has a property onInit you can use, for instance:
async onInit(payload) {
const existingUsers = await payload.find({
collection: adminCollection.slug,
limit: 1,
})
if (existingUsers.docs.length === 0) {
// run seed code
)
)
But onInit only execute when admin page is visited or restful api is called
It also runs when you visit your frontend
I mean I'm using payload 3.0 beta, should precise that, so its coupled with nextjs
I see
this is good to know
Star
Discord
online
Get dedicated engineering support directly from the Payload team.