mgfy (short for magnify) is built to be a quick and easy way to get
information from MongoDB without leaving the terminal. Have you ever forgotten
the precise name of the collection you need to write to, wanted to know how much
disk space is being used, or just needed an example document to remember the
schema that you're working with? That's exactly what mgfy does.
Right now mgfy can only be installed using the Rust
Toolchain. Like all other binary crates,
it can be installed with:
cargo install mgfymgfy allows you to define and save parameters to easily switch between
separate connections. Each connection is defined by the following fields:
| Field | Description |
|---|---|
| name | A unique name for the connection; this will be used to specify which connection to use in subsequent commands |
| host | hostname used in the connection string (e.g. "localhost") |
| port | port used in the connection string (e.g. 27017, MongoDB's default |
| protocol | The first portion of the connection string (default: "mongodb") |
| default | Flag for whether this should be the default connection |
There are a few commands for managing connections, they are:
create-connection: uses the specified parameters in creating a new connectionlist-connections: lists the connections that have been saved- TODO
remove-connection: deletes a saved connection - TODO
set-default-connection: sets the named connection to be the default
There are a number of commands that are built into mgfy so far:
estimate-document-count: will return the document count from the collection metadataexample: gets an example document from the collection without filteringexmaple-filtered: gets an example document from the collection after filtering on the user-provided querylist-collection-details: returns the name, document count, size, and allocated storage for each collection in a databaselist-collections: returns the name of all the collections in a databaselist-databases: returns all of the database names
Here's the help text:
$ mgfy -h
A command line tool for inspecting MongoDB
Usage: mgfy [OPTIONS] <COMMAND>
Commands:
create-connection Create a new connection
estimate-document-count Returns the document count in the metadata for the collection
example Get an example document
example-filtered Get an example document after filtering
list-collection-details Get detailed information on each collection
list-collections List the collections in a database
list-connections List connections
list-databases List the databases
help Print this message or the help of the given subcommand(s)
Options:
-n, --name <NAME> Name of the connection to use (see list-connections command)
-h, --help Print help
-V, --version Print versioGetting Rust to interpret an input string as JSON is not trivial. The following is a working example:
mgfy example-filtered foo bar '{"Hello": {"$exists": true}}'