Skip to content

Instantly share code, notes, and snippets.

@v-stickykeys
Last active September 22, 2018 17:59
Show Gist options
  • Save v-stickykeys/abcc9be4e5539d5fe874bd73f3699637 to your computer and use it in GitHub Desktop.
Save v-stickykeys/abcc9be4e5539d5fe874bd73f3699637 to your computer and use it in GitHub Desktop.
mongo commands I need to know

Connect to mongo

$ mongo

What db am I in?

> db

What dbs do I have?

> show dbs

Switch into a db

> use dbToSwitchTo

Create a new db

> use nameOfNewDb

The db won't be permanent until data is added to a collection inside of it

What collections do I have?

> show collections

Create and add data to a collection

> db.firstCollection.insertOne({x:1});

db is a variable representing the current db I am in

To be continued.. db.createCollection(name, {size: ..., capped: ..., max: ...})

db.createUser({ user: "nameOfUser",
                pwd: "pwOfUser",
                roles: [{ role: "readAnyDatabase", db: "admin" }, "readWrite"]
              });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment