artsy/mongoid-shell

Name: mongoid-shell

Owner: Artsy

Description: Derive shell commands from Mongoid sessions and configuration options.

Forked from: dblock/mongoid-shell

Created: 2017-12-05 09:23:11.0

Updated: 2017-12-05 09:23:13.0

Pushed: 2017-12-06 21:27:32.0

Homepage: null

Size: 106

Language: Ruby

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Mongoid::Shell

Gem Version Build Status Dependency Status Code Climate

Create mongo command-lines from Mongoid configuration.

For example, connect to your production database without having to remember the entire command line using a db:production:shell Rake task.

space :db
mespace :production
task :shell
  Mongoid.load! File.join(Rails.root, "config/mongoid.yml"), :production
  system Mongoid::Shell::Commands::Mongo.new.to_s
end
d

Commands can be created for the current default session or you can pass a session as an argument to a new command.

oid::Shell::Commands::Mongodump.new # will use Mongoid.default_session
oid::Shell::Commands::Mongodump.new(session: Moped::Session.new([ "127.0.0.1:27017" ]))

Commands accept parameters.

= File.join(Dir.tmpdir, 'db_backup')
odump = Mongoid::Shell::Commands::Mongodump.new(db: 'another_database', out: out)
em mongodump.to_s # mongodump --db another_database --out /tmp/db_backup

To specify parameters multiple times, set them to arrays.

odump = Mongoid::Shell::Commands::Mongodump.new(excludeCollection: %w(users products))
em mongodump.to_s # mongodump --excludeCollection users --excludeCollection products
Compatibility

This gem supports Mongoid 3, 4, 5 and 6.

Supported Commands
Mongo

The mongo shell is an interactive JavaScript shell for MongoDB. The Mongoid::Shell::Commands::Mongo class generates a command line to connect to MongoDB. A particularly useful feature is that it will always yield the address of the master node of a MongoDB replica set.

oid::Shell::Commands::Mongo.new.to_s

Supports --username, --password, --eval, --nodb, --norc, --quiet and --ipv6.

Mongodump

Mongodump is a utility for creating a binary export of the contents of a database.

odump = Mongoid::Shell::Commands::Mongodump.new(collection: 'test')
odump.to_s # mongodump --db test --collection test

The Mongoid::Shell::Commands::Mongodump class supports --db, --host, --username, --password, --query, --out, --collection, --excludeCollection, --excludeCollectionsWithPrefix, --directoryperdb, --journal, --oplog, --repair, --forceTableScan, --dbpath and --ipv6.

Mongorestore

The mongorestore tool imports content from binary database dump, created by mongodump into a specific database.

orestore = Mongoid::Shell::Commands::Mongorestore.new(collection: 'test', restore: '/tmp/db_backup')
orestore.to_s # mongorestore --db test --collection test /tmp/db_backup

The Mongoid::Shell::Commands::Mongorestore class supports --db, --host, --username, --password, --collection, --ipv6, --dbpath, --directoryperdb, --journal, --objcheck, --filter, --drop, --oplogReplay, --keepIndexVersion and --noIndexRestore.

Mongoexport

The mongoexport tool produces a JSON or CSV export of data stored in a MongoDB instance.

oexport = Mongoid::Shell::Commands::Mongoexport.new(collection: 'traffic', out: 'traffic.json')
oexport.to_s # mongoexport --db test --collection traffic --out traffic.json

The Mongoid::Shell::Commands::Mongoexport class supports --verbose, --quiet, --version, --port, --ipv6, --ssl, --sslCAFile, --sslPEMKeyFile, --sslPEMKeyPassword, --sslCRLFile, --sslAllowInvalidCertificates, --sslAllowInvalidHostnames, --sslFIPSMode, --authenticationDatabase, --authenticationMechanism, --gssapiServiceName, --gssapiHostName, --collection, --fields, --fieldFile, --query, --csv, --type, --out, --jsonArray, --pretty, --slaveOk, --forceTableScan, --skip, --limit, --sort, --directoryperdb, --journal, --dbpath.

Mongoimport

The mongoimport tool imports content from an Extended JSON, CSV, or TSV export created by mongoexport, or potentially, another third-party export tool.

oimport = Mongoid::Shell::Commands::Mongoimport.new(collection: 'contacts', file: 'contacts.json')
oimport.to_s # mongoimport --db test --collection contacts --file contacts.json

The Mongoid::Shell::Commands::Mongoimport class supports --verbose, --quiet, --version, --host, --username, --password, --port, --ipv6, --ssl, --sslCAFile, --sslPEMKeyFile, --sslPEMKeyPassword, --sslCRLFile, --sslAllowInvalidCertificates, --sslAllowInvalidHostnames, --sslFIPSMode, --authenticationDatabase, --authenticationMechanism, --gssapiServiceName, --gssapiHostName, --db, --collection, --fields, --directoryperdb, --journal, --dbpath, --fieldFile, --ignoreBlanks, --type, --file, --drop, --headerline, --upsert, --upsertFields, --stopOnError, --jsonArray, --maintainInsertionOrder, --numInsertionWorkers, --writeConcern.

Mongostat

The mongostat utility provides a quick overview of the status of a currently running mongod or mongos instance.

The Mongoid::Shell::Commands::Mongostat class supports --host, --username, --password, --rowcount, --discover, --noheaders, --http and --all.

Contributing

Fork the project. Make your feature addition or bug fix with tests. Send a pull request. Bonus points for topic branches.

Copyright and License

MIT License, see LICENSE for details.

(c) 2013-2016 Daniel Doubrovkine, Artsy Inc.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.