mongovi

REPL for mongodb with vi key bindings

mongovi

Mongovi is a small REPL for MongoDB with vi key bindings. See the list of supported methods by node-mongodb-native. And the list of supported vi key bindings by readline-vim.

$ sudo npm install -g mongovi

open shell for database bar:

$ mongovi bar

print names of all databases:

> show dbs
foo
bar
> 

print name of current database:

> db
bar
> 

switch to another database:

> use foo
foo 2 collections
> 

list collections in current database:

> c
bar
baz
> 

list contents of collection baz:

> c.baz.find();
{"_id":"52378623870dd40000000001", "foo": "bar" }
{"_id":"52378623870dd40000000002", "foo": "baz" }
> 

list contents of collection baz with a callback:

> c.baz.find().toArray(function(err, items) { console.log(err, items.length); });
> null 2

update item in collection baz:

> c.baz.update({ _id: new ObjectID('52378623870dd40000000001') }, { foo: 'quux' });
> 

insert item into collection baz:

> c.baz.insert({ foo: 'qux' });
> 

drop collection baz:

> c.baz.drop()
> 

drop current database:

> db.dropDatabase()
> 

Database access information is read from .mongovi.json in the users home directory if it exists.

{
  "user":   "joe",
  "pass":   "foo",
  "db":     "bar",
  "authDb": "admin",
  "host":   "127.0.0.1",
  "port":   27017
}

Show all command-line options with mongovi --help. These options override any config file setting.

Usage: mongovi [options] [-d] dbname

Options:

  -h, --help             output usage information
  -V, --version          output the version number
  -d, --db <dbname>      database name, default admin
  -p, --port <number>    port, default 27017
      --host <address>   hostname, default 127.0.0.1
  -u, --user <username>  username to authenticate
  -v, --verbose          show debugging information

switch to a database named foo

show the list of databases, comparable with:

db.admin().listDatabases(function(err, dbs) {
  console.log(dbs);
});

show the list of collections in the current database, comparable with:

db.collectionNames(function(err, collections) {
  console.log(collections);
});

alias for c

print the name of the database currently selected

  • where foo is a method supported by mongodb.Db. If no callback is provided on any of these methods the results are automatically printed.
  • where foo is the name of a collection in the current database.
  • where bar is a method supported by mongodb.Collection. If no callback is provided on any of these methods the results are automatically printed.

c.foo.find() is a shortcut for:

c.foo.find().toArray(function(err, items) {
  items.forEach(function(item) {
    console.log(JSON.stringify(item));
  });
});

the raw mongodb object

alias for mongodb.ObjectID

alias for mongodb.Timestamp

ISC

Copyright (c) 2013, 2014, 2015 Tim Kuijsten

Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.