Skip to content

Command console

  • MongoDB

The command console runs MongoDB command documents, such as { find: … }, { aggregate: … } or { collStats: … }, against the database you pick. The documents a command returns show in the same tree, table and JSON views as the collection view, and the server’s messages in a separate tab. Every run goes into the query history.

Each run takes one command document. To write a query as db.products.find(…), use the find() text of the collection view instead.

  1. Open a console: choose Open console from a database’s or collection’s menu in the explorer, or New query tab from the connection’s menu.

  2. Pick the Database the command runs against.

  3. Type a command document in Extended JSON or mongosh syntax:

    { find: "products", filter: { price: { $gt: 500 } }, sort: { price: -1 }, limit: 20 }
  4. Choose Run, or press Ctrl + Enter (Cmd + Enter on macOS).

Commands that return a cursor, such as find, aggregate or listCollections, stream a page at a time and fetch more as you scroll. Cancel stops a running command.

  • Results shows the documents in the Tree, Table or JSON view. The footer shows the connection, the server version and how many documents were returned.
  • Messages lists the run’s messages with their time; a count of errors appears on the tab.

Console results are read-only. To edit documents, use the collection view.

Connection What happens
Read-only Commands that write are refused.
Production, or confirm writes Every command that writes asks first.
Any Destructive commands, such as { drop: "customers" }, ask first.

Declining the confirmation runs nothing.

querybara query runs the same command documents against a saved profile or a MongoDB URI. An array of commands runs in order. The documents print as relaxed Extended JSON; --format json prints canonical Extended JSON as one array and --format jsonl one document per line.

Terminal window
querybara query "mongodb://[email protected]:27017/catalog" -e '{ find: "products", filter: { price: { $gt: 500 } } }'
querybara query "mongodb://[email protected]:27017/catalog" -f commands.json --format jsonl

The same write rules apply: --read-only refuses commands that write, and destructive commands ask in a terminal or need --yes.

Documents Querybara 0.1.1 · built frombc9f5aa