MONGOVI(1) | General Commands Manual | MONGOVI(1) |
mongovi
— command
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.
-p
-s
.-s
-p
.-i
mongovi
commands.-V
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:
find
[selector]-s
).
If not connected to a terminal then documents are output in canonical
MongoDB Extended JSON format (which can be overridden with
-p
).count
[selector]remove
selectorupdate
selector docupsert
selector docinsert
docaggregate
[pipeline]cd
[path]mongovi
started is selected. See
PATH ARGUMENT for more info.cd
old newls
[path ...]drop
[path ...]help
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
Tim Kuijsten
November 15, 2016 | Debian |