grunt-mongo-bin v0.1.0
grunt-mongo-bin
Run MongoDB CLI tasks the easy way. Import, export, dump, restore, and more!
mongobin is basically just an easy way to hook grunt into the mongodb/bin executables. It was designed to incorporate data backup and restoration into the grunt pipeline, but it could as easily be used to start and stop the daemon, echo stats, and so on. The best part is that it helps keep your workflow tight and your settings orderly.
Getting Started
This plugin requires Grunt.
If you haven't used Grunt before, be sure to check out the Getting Started guide, as it explains how to create a Gruntfile as well as install and use Grunt plugins. Once you're familiar with that process, you may install this plugin with this command:
npm install grunt-mongo-bin --save-dev
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
grunt.loadNpmTasks('grunt-mongo-bin');
The "mongobin" task
Overview
In your project's Gruntfile, add a section named mongobin
to the data object passed into grunt.initConfig()
. Options may be specified for all tasks, or for individual tasks, as seen below:
grunt.initConfig({
mongobin: {
options: {
host: 'localhost',
port: '27017',
db: 'test-db'
},
restore_terms: {
task: 'restore',
collection: 'terms',
path: './dump/default'
},
dump: {
// if task is unspecified, mongobin will attempt to use the target key,
// in this case, 'dump'.
out: './dump/' + Date.now()
}
},
});
Options
Most options are drawn directly from the mongo executables. Please see the mongo docs for more info.
Custom options follow:
options.task
Type: String
Default value: undefined
This is the task one wishes to run. Includes mongod
, mongodump
, mongorestore
, mongoimport
, mongoexport
, mongofiles
, etc. Handy aliases are available, such as daemon
, dump
, restore
, import
, export
, files
, and so on.
If no task is specified, mongobin will attempt to use the task target, so you can use targets such as log
, perf
, shard
, bson
, etc.
options.bin
Type: String
Default value: undefined
If you have not included mongodb/bin in your system path, you can specify it's using this option. Handy for portable installs and lazy people.
Examples
More to come...
BSON dump and restore
This'll let you dump make timestamped dumps, and, after renaming one of them 'default', will allow you to refresh your database with a standard dataset.
grunt.initConfig({
mongobin: {
options: {
host: 'localhost',
port: '27017',
db: 'test-db'
},
restore: {
path: './dump/default',
drop: true
},
dump: {
out: './dump/' + Date.now()
}
},
});nMpP3Go1
Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.
Release History
- 0.1.0 ** First release. Basic functionality. Direct options -> args path with some shortcuts built in.
License
Copyright (c) 2014 Mike Stop Continues. Licensed under the MIT license.
11 years ago