The ultimate CLI tool for populating your MongoDB database 馃殌
Define MongoDB documents in JSON, JavaScript or even TypeScript file(s). Import them with command line interface.
To install the app, run the following command:
npm install -g mongo-seeding-cli
Before you begin, follow the tutorial to define documents and collections to import. See samples
directory for examples.
In order to seed your database with data from current directory using default configuration, run the following command:
seed
You can specify custom settings with command line parameters. The following example imports data from ./example/data
directory using MongoDB connection URI mongodb://127.0.0.1:27017/mydb
:
seed -u 'mongodb://127.0.0.1:27017/mydb' -d ./example/data
You can also use environmental variables to configure the CLI. For example:
DB_URI='mongodb://127.0.0.1:27017/mydb' seed -d ./example/data
Full configuration options are described in Configuration section.
You can configure data import with command line parameters or environmental variables.
Note: Command line parameters have always a higher priority over environmental variables.
You can use the following parameters while using seed
tool:
Name | Default Value | Description |
---|---|---|
--data {PATH} or -d {PATH} |
current directory | Path to directory containing import data |
--db-uri {URI} or -u {URI} |
undefined |
If defined, the URI will be used for establishing connection to database, ignoring values defined via other db-* parameters (e.g. db-name , db-host , etc.) |
--db-protocol {DB_PROTOCOL} |
mongodb |
MongoDB database protocol |
--db-host {DB_HOST} |
127.0.0.1 |
MongoDB database host |
--db-port {DB_PORT} |
27017 |
MongoDB database port |
--db-name {DB_NAME} |
database |
Name of the database |
--db-username {DB_USERNAME} |
undefined |
Username for connecting with database that requires authentication |
--db-password {DB_PASSWORD} |
undefined |
Password for connecting with database that requires authentication |
--drop-database |
false |
Dropping entire database before data import |
--drop-collection |
false |
Dropping every collection that is being imported |
--replace-id |
false |
Replacing id property with _id for every document during data import |
--reconnect-timeout |
10 (seconds) |
Maximum time of waiting for successful MongoDB connection |
--help or -h |
n/a | Help |
You can use the following environmental variables while using seed
tool:
Name | Default Value | Description |
---|---|---|
DB_URI | undefined |
If defined, the URI is used for establishing connection to database, ignoring values given in DB_* environmental variables (e.g. DB_HOST , DB_PORT , etc.). |
DB_HOST | 127.0.0.1 |
MongoDB database host |
DB_PORT | 27017 |
MongoDB database port |
DB_NAME | database |
Name of the database |
DB_USERNAME | undefined |
Username for connecting with database that requires authentication |
DB_PASSWORD | undefined |
Password for connecting with database that requires authentication |
DROP_DATABASE | false |
Dropping entire database before data import |
DROP_COLLECTION | false |
Dropping every collection that is being imported |
REPLACE_ID | false |
Replacing id property with _id for every document during import; useful for ORMs |
RECONNECT_TIMEOUT | 10 |
Maximum time, in which app should keep trying connecting to database |