MONGOVI(1) General Commands Manual MONGOVI(1)

mongovicommand line interface for MongoDB

mongovi [-psV] [path]

mongovi -i path

mongovi is a cli for MongoDB that uses editline(3) for line editing and key bindings. It can be used both interactively and non-interactively i.e. via shell scripts.

Print output in a human readable format. This is the default when stdout is connected to a terminal. Mutually exclusive with -s.
Print each JSON document on a single line in canonical MongoDB Extended JSON format. This is the default when stdout is not connected to a terminal. Mutually exclusive with -p.
Import mode. Read MongoDB Extended JSON documents from stdin and insert them into the database. Each line must contain one document and not any mongovi commands.
Print version information and exit.
path
Open a specific database or collection. See PATH ARGUMENT for more info.

The default key bindings are Emacs-like. vi(1)-like key bindings can be enabled by putting "bind -v" into the editrc(5) file.

By default mongovi will connect to mongodb://localhost:27017 unless it is overridden with a connection string in ~/.mongovi.

The following commands are supported:

[selector]
List all documents in the currently selected collection. If connected to a terminal then documents are output in a human readable format (which can be overridden with -s ). If not connected to a terminal then documents are output in canonical MongoDB Extended JSON format (which can be overridden with -p ).
[selector]
Count all documents in the currently selected collection.
selector
Remove all documents in the currently selected collection that match the selector.
selector doc
Update all documents that match the selector using the provided update document.
selector doc
Update or insert a document that matches the selector using the provided document.
doc
Insert doc into the currently selected collection. doc is parsed as MongoDB Extended JSON.
[pipeline]
Run an aggregation query using the given pipeline.
[path]
Change the currently selected database or collection to path. If path is a single dash (‘-’) the previous path will be selected. If path is absent the first path since mongovi started is selected. See PATH ARGUMENT for more info.
old new
The string new is substituted for old in the currently selected path.
[path ...]
List the contents of each path. If path is absent the currently selected path is used.
[path ...]
Drop the collection or database described by each path. In case path is absent the currently selected path is dropped.
Print the list of commands.

Any command can be abbreviated to the shortest non-ambiguous form. So find can also be written as f since no other command starts with an f.

If selector is not a JSON document it is treated as a shortcut to search on _id of type string. Hexadecimal strings of 24 characters are treated as object ids.

Several commands take a path parameter. A path can be seen as a file hierarchy in which the root contains one directory per database and where each database contains one directory per collection. A path without a leading "/" is treated as a path relative to the currently selected database or collection. A path that starts with a "/" is considered an absolute path. A ".." component can be used to traverse up in the hierarchy.

~/.mongovi If it exists the first line is read and used as a MongoDB connection string. This string can contain a username and password.

The mongovi utility exits 0 on success, and >0 if an error occurs.

List all databases non-interactively:

$ echo ls | mongovi

Open database "foo" and collection "bar":

$ mongovi /foo/bar
/foo/bar>

Change the currently selected collection to "sabar":

/foo/bar> cd ../sabar
/foo/sabar>

List documents where "foo" is "bar":

/foo/bar> f { foo: "bar" }

Quick search on Object ID:

/foo/bar> f 57c6fb00495b576b10996f64

Use an aggregation query to filter on documents where "foo" is "bar". Note that aggregate is abbreviated to a:

/foo/bar> a [{ $project: { foo: true } }, { $match: { foo: "bar" } }]

Copy one collection to another:

$ echo f | mongovi /foo/bar | mongovi -i /qux/baz

editrc(5), editline(7)

Connection String URI Format, MongoDB Extended JSON (v2)

Tim Kuijsten

November 15, 2016 Debian