How to use the mongo-seeding.Seeder function in mongo-seeding

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 / 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);

mongo-seeding

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

MIT
Latest version published 5 months ago

Package Health Score

72 / 100
Full package analysis