Skip to content

Instantly share code, notes, and snippets.

@somahargitai
Last active July 18, 2019 08:59
Show Gist options
  • Save somahargitai/91e61883609e2cb0642e885da1cf951e to your computer and use it in GitHub Desktop.
Save somahargitai/91e61883609e2cb0642e885da1cf951e to your computer and use it in GitHub Desktop.
My Notes on creating and handling MongoDB, DynamoDB or other NoSQL databases.

cheatsheet list

MongoDB

Create and start

  • Windows create a mongodb folder in C: (or wherever you want)
    mongod --directoryperdb --dbpath C:\mongodb\data\db --logpath C:\mongodb\log\mongo.log --logappend --rest --install

net start MongoDB - start it with net which is to handle services

start mongo shell: mongo

shell commands:

  • cls - clear
  • show dbs - show db list
  • db - show active db
  • use mycustomers - create new db and switch to it
  • db.createUser(.....); - check documentation to find out standard input format
  • db.createCollection('customers'); - create a collection called customers
  • show collections
  • db.customers.insert(....);
  • db.customers.find();
  • db.customers.find().pretty(); - tabulated print
  • db.customers.update({field1: "one"}, {field1: "one", field2: "two"}); - this will update all the objects which have "one" as "field1" value with the object given as the second argument
  • db.customers.find().count; - count elements. You can put conditions to find() arguments
  • db.customers.find.limit(4); - show only the first 4 objects found
  • db.customers.find.limit(4).sort({ field: -1 }); - show 4, sort them in descending order (ascending would be 1)
  • db.customers.find().forEach(function(doc){print("Customer Name: "+doc.fieldname)}); - Print all the "fieldname" fields found with the query with the starting text in every line "Customer Name :"

Notes based on Traversy media crash course

DynamoDB

A very short intro: Create a dynamoDB on AWS dashboard

You can find local DynamoDB download options on AWS docs, but the best solution seems to be to run it in a Docker container. AWS provides a java sample application here

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