Adding a bunch of choices/data

Hey, loving Strapi so far, it’s just what I’m looking for.

I installed the starter project Next blog, and wanted to see if it’s possible to add dozens of new Authors into the data. There’s a collection type called “Article”, and a field called “Author”. Let’s say for the sake of argument that my blog is going to have dozens of authors. Rather than manually adding them one by one into the writer content type, is there a way to batch import all of them?

I tried editing c:\Users–username–\Projects–projectname–\backend\data\data.json and restarting the development server, but that didn’t seem to do anything.

You can create your own startup script in config/functions/bootstrap.js to then populate the data.

As an example I’m creating an admin on startup with this script

createDB: async (data, db) => {
    const exist = await strapi.query(db).find({ _limit: 1 });
    if (exist.length === 0) {
      await _populateDB(data, db);
    } else {
      console.log(`${_.capitalize(db)} already exists`);
    }
  },
_populateDB = async (data, db) => {
  console.log('Populated database:', _.capitalize(db));
  switch (db) {
    case 'countries':
      data.forEach((seed) => {
        strapi.query(db).create({
          name: seed.name,
          countryCode: seed.countryCode,
          enabled: seed.enabled,
          favourite: seed.favourite,
          currencyCode: seed.currencyCode
        });
      });
      break;

    default:
      data.forEach((seed) => {
        strapi.query(db).create({
          name: seed
        });
      });
      break;
  }
};

I’m then calling I in bootstrap.js with await createDB(countries, 'countries'); The languages`
the countries variable here I’m using is pulling data from a json file etc. So you can adjust it accordingly.