Cheat Sheet

MongoDB Cheat Sheet

  • By
    Cian Clarke
  • Published: 2017-03-24
Cover image for the MOngoDB cheat sheet
MongoDB Cheat Sheet

There are many GUI tools to connect to MongoDB databases and browse but sometimes you need to get to the command line. That moment when something has gone wrong on the database server, and you need to SSH 4-levels deep in order to debug a problem with a database can leave you stuck.

In this cheat sheet you can get a quick refresher on:

  • Starting the mongo shell
  • Navigating around Mongo
  • Working with a collection
  • Changing groups of documents
  • Working with individual documents and Indexes
  • Dangers to avoid

Created for personal use by Red Hat’s own Cian Clarke, we’ve cleaned it up a bit for your use.

Cheat Sheet Excerpt

Navigating around Mongo

Here are the most used commands, operations and queries.

Help Methods and Commands
Description
show dbs
Shows all databases available on this server
use acmegrocery
Switches to a database called acmegro- cery. Creates this database if it doesn’t already exist.
show collections
Show all collections in the current db (first `use ‹someDb›`)
show users
Show all users for the current DB
show roles
Show the roles defined for the current DB
Want to see more? Get the full cheat sheet.

Comments