Skip to content

Instantly share code, notes, and snippets.

@GoodGuyGregory
Last active May 1, 2020 12:54
Show Gist options
  • Save GoodGuyGregory/dfeb35e05f8a469f77dbed25d04d2ffa to your computer and use it in GitHub Desktop.
Save GoodGuyGregory/dfeb35e05f8a469f77dbed25d04d2ffa to your computer and use it in GitHub Desktop.

Getting Started

Mongo on Docker

Mongo Commands for Docker

  • Build the container

docker run --name some-mongo -v $PWD/data:/data/db -p 27017:27017 -d mongo

  • import data

mongoimport --db students students.json

  • build with docker exec to allow commands inside of the container

docker exec -it some-mongo mongo

  • complete the assignment

Mongo Commands inside of DataGrip

Vist Cloud hosted Mongodb

grab configuration from the cluster

  • Import into Datagrip

from + icon from the connection list

Commands

Basic Commands

mongo - starts the mongo shell

show dbs - lists all dbs in the mongo shell

use <db name> - switches to the db in question

Collections

db.shipment.createIndex({name: 1, street: 1, zip:1}) - creates a collection of shipments with name, street, and zip, attributes in ascending order

db.<collection>.getIndexes() - returns the number of items in the collection

db.<collection>.find() - lists all indexes/entries in a collection

db.<collection>.aggregate({}) allows for nested queries and aggregate pipeline queries using $count, $match, $group etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment