gomon
========
MongoDB shell written in Node.js
Experimental
Usage
$ gomon --help
Usage: gomon [options] [db address] [file names]
Options:
-h, --help output usage information
-V, --version output the version number
--port <port> port to connect to
--host <host> server to connect to
-e --eval <code> evaluate script
-v --version print gomon's version
--shell run the shell after executing files
db address:
foo foo database on local machine
192.169.0.5/foo foo database on 192.168.0.5 machine
192.169.0.5:9999/foo foo database on 192.168.0.5 machine on port 9999
mongodb://host:port/db mongo URI
file names:
List of space delimited files (ending in .js) to execute.
When passed, the shell exits after execution unless --shell
is specified.
Example
$ gomon mongodb://localhost:27017,hostA:27017,hostB/dev
gomon version 0.0.3
connecting to mongodb://localhost:27017,hostA:27017,hostB/dev
gomon>
API
show.dbs
: List available databasesshow.collections
: List available collections in current databaseshow.tables
: Alias ofshow.collections
use[databaseName]
: Switch databasesexit
: Exits the shelldb.close()
: Closes the database connectiondb.col()
: Accesses a collectiondb.cols()
: Retreives an array of collection names in the dbdb.createCol()
: Creates a collectiondb.drop()
: Drops the databasedb.help()
: Logs help text for all db methodsdb.inspect()
: Returns the name of the databasedb.open()
: Opens the database connectiondb.runCommand()
: Runs a command on the databasedb.use()
: Changes to a different databasedb.collection.findOne()
: Find a single document
More to come.
Example:
First we connect to fakehost.
$ gomon --host fakehost
gomon version 0.0.3
connecting to mongodb://fakehost
gomon>
Next we list the available databases()
gomon> showdbstest 0203125GBfake 0203125GBdev 0203125GB
Switch to the dev database
gomon> usedev
For autocompletion, type use.<TAB>
to see a list of available databases.
Display the dev database collections
gomon> showcollectionssystemindexesusersproducts
Get a count of the users collection
gomon> dbusersgomon> null 1
Look up a user
gomon> dbusersgomon> null _id: 50f99acfc50ea8c8ef23142c name: 'gomon was here'
p
is a global helper for queries that performs pretty printing on results.
gomon> dbusersgomon>error: null _id: 50f99acfc50ea8c8ef23142c name: 'gomon was here'
Files
All arguments ending in .js
will be treated as files and executed.
// script1.jsconsole; // command line$ gomon script1jsgomon version 003connecting to mongodb://localhost:27017/testgomongo------------------------------------------ waiting for script to call `exit;` ... OR press Ctrl+D to quit immediately------------------------------------------gomon>
When files are passed, the shell will not automatically exit. This is so that async operations within scripts are not stopped prematurely. Your scripts must manage themselves, e.g. when all operations are completed, call exit;
.
Eval
Code may be evaled and printed to the shell by passing the -e
or --eval
flag.
$ gomon --eval "db.databaseName + ' is the default db'"
gomon version 0.0.3
connecting to mongodb://localhost:27017/test
test is the default db
bye
The shell will immediately exit after script evaluation unless the --shell
flag is passed.
Debugging
Enable debugging output:
DEBUG=gomon gomon localhost:27017