Socket
Socket
Sign inDemoInstall

mongo-seeding-cli

Package Overview
Dependencies
50
Maintainers
1
Versions
40
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    mongo-seeding-cli

Fill your MongoDB database with data in easy way with CLI. Use JavaScript and JSON files to define the data!


Version published
Maintainers
1
Install size
3.78 MB
Created

Readme

Source

Mongo Seeding CLI

Fill your MongoDB database with data in easy way with CLI. Use JavaScript and JSON files to define the data!

npm Open Source Love

If this is not what are you looking for...

Installation

npm install -g mongo-seeding-cli

Usage

seed --db-host 0.0.0.0 --db-name testing2 -d ./samples/data/ --drop-database --convert-id

Command Line Parameters

NameRequiredDefault ValueDescription
--data $PATH or -d $PATHyes-Path to directory containing import data structure specified above
--db-host $DB_HOSTno127.0.0.1MongoDB database host
--db-port $DB_PORTno27017MongoDB database port
--db-name $DB_NAMEnodatabaseName of the database
--drop-databasenofalseIf parameter specified, drop database before importing data
--convert-idnofalseIf parameter specified, replaces id field with _id for every object it imports

Prepare your data to import

  1. Create a new directory. In this example, name it simply as data.

  2. This directory data will contain subdirectories in following naming convention: $NUMBER-$COLLECTION_NAME - i.e. 1-categories, 2-posts.

    $COLLECTION_NAME - it's just a collection name that will be created if not exist.

    $NUMBER - to define collections import order. If you don't care about import order - just name the directory as $COLLECTION_NAME, i.e. categories.

  3. In every collection directory you can create multiple files in formats: .js and .json. You can define object or array of objects.

    For JS files: Export object or array of objects you want to import via module.exports = objectOrArray

    Every object is a representation of document in MongoDB database.

  4. The whole file structure should look like this:

    data
    +-- tsconfig.json // Optional for using TypeScript (see Advanced )
    +-- 1-categories
    |   +-- cat.js
    |   +-- dogs.js
    |   +-- other-animals.json
    +-- 2-posts
    |   +-- post-about-my-cat.json
    |   +-- dog-posts.js
    |   +-- random-stuff.js
    +-- 3-media
    |   +-- cat-image.js
    |   +-- dog.js
    

Samples

Take a look at samples repository to see Mongo Seeding in action!

Keywords

FAQs

Last updated on 10 Jan 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc