How to use mongo-seeding - 4 common examples

To help you get started, we’ve selected a few mongo-seeding examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github davellanedam / node-express-mongodb-jwt-rest-api-skeleton / seed.js View on Github external
require('dotenv-safe').config()
const { Seeder } = require('mongo-seeding')
const path = require('path')
const config = {
  database: process.env.MONGO_URI,
  inputPath: path.resolve(__dirname, './data'),
  dropDatabase: false
}
const seeder = new Seeder(config)
const collections = seeder.readCollectionsFromPath(path.resolve('./data'))

const main = async () => {
  try {
    await seeder.import(collections)
    console.log('Seed complete!')
    process.exit(0)
  } catch (err) {
    console.log(err)
    process.exit(0)
  }
}

main()
github pkosiec / mongo-seeding / docker-image / src / index.ts View on Github external
(async () => {
  try {
    await seedDatabase(envOptions);
  } catch (err) {
    console.error(`Error ${err.name}: ${err.message}`);
    process.exit(1);
  }
})();
github pkosiec / mongo-seeding / cli / src / index.ts View on Github external
if (shouldShowHelp(options)) {
      showHelp();
      return;
    }

    try {
      validateOptions(options);
    } catch (err) {
      this.printError(err);
      return;
    }

    const config = createConfigFromOptions(options);
    this.useCliSpecificOptions(config as DeepPartial);
    const seeder = new Seeder(config as DeepPartial);

    const collectionsPath = this.getCollectionsPath(options);
    const collectionReadingConfig = this.getCollectionReadingConfig(options);

    try {
      const collections = seeder.readCollectionsFromPath(
        resolve(collectionsPath),
        collectionReadingConfig,
      );

      await seeder.import(collections);
    } catch (err) {
      this.printError(err);
    }

    process.exit(0);
github pkosiec / mongo-seeding / cli / src / index.ts View on Github external
private getCollectionReadingConfig = (
    options: CommandLineArguments,
  ): SeederCollectionReadingOptions => {
    const transformers = [];
    const replaceIdWithUnderscoreId =
      options['replace-id'] || process.env.REPLACE_ID === 'true';

    if (replaceIdWithUnderscoreId) {
      transformers.push(Seeder.Transformers.replaceDocumentIdWithUnderscoreId);
    }

    return {
      extensions: ['ts', 'js', 'json'],
      transformers,
    };
  };

mongo-seeding

The ultimate Node.js library for populating your MongoDB database.

MIT
Latest version published 1 month ago

Package Health Score

78 / 100
Full package analysis