How to seed MongoDB Database?
Unanswered
Pollock posted this in #help-forum
PollockOP
Hello, I'm having difficulties seeding my mongodb database. I tried writing a .js script to run in node - but I cant run the scripts as it doesn't like import statements.
8 Replies
@Pollock Hello, I'm having difficulties seeding my mongodb database. I tried writing a .js script to run in node - but I cant run the scripts as it doesn't like import statements.
you can use .mjs to use import/export and modules
PollockOP
Thanks for replying. I'll look into what that is. Is this a good way in general to seed a database in nextjs with mongodb?
@Pollock Thanks for replying. I'll look into what that is. Is this a good way in general to seed a database in nextjs with mongodb?
it's not good or bad, you use db seeding when you need it
@Pollock Thanks for replying. I'll look into what that is. Is this a good way in general to seed a database in nextjs with mongodb?
Depending on how much data you have, I like to seed my db when my first user joins or my app starts up for the first time or I have a “seed†route behind an api key which gets invoked
But in my case the seed data is usually like 100 records or less
So it runs in an acceptable amount of time
PollockOP
not having any luck switching to .mjs
I guess I could have the seed code run on my sign in, then comment it out after - but that seems rather janky