Giter Club home page Giter Club logo

pokemon-mongo-robot's Introduction

mongodb-demo

pokemon are cool

Startup

Mongo as a Docker container

run in docker container and expose mongo port 27017 on localhost docker run -d --rm --hostname mongo --name mongo -p 27017:27017 mongo

MongoDb

ways to connect:

Dive into MongoDb inside a docker container

  • docker exec -it <CONTAINER_ID> /bin/bash then mongo
  • or directly docker exec -it <CONTAINER_ID> mongo

MongoDb Architecture

  • physical database, i.e. the mongodb server
  • logical databases (db) - e.g. for each application/service a different database
  • collections - e.g all users
  • namespace = a logical db + a collection
  • documents - e.g. a single user

Relational DBs vs non-relational DBs

Relational Dbs (SQL) Non-relational (document-based, No-SQL)
schema-based (think classes) schema-less (think json object)
tables collections
records documents
data format is pretty much known up front rapid prototyping
very fast fast but in some use-cases...
normalized not normalized
avoids inconsistencies accepts/manually resolves inconsistencies
(almost) no duplication duplication somtimes accepted
good for communication /forced to document (by schema) (by default) no documentation, just data
"type-safe" flexible
migrations needed no migrations since no schema, but for data

Mongo CLI usage

Cheatsheet

show dbs
use pokemonDB
db.createCollection('pokemon')
db.createCollection('trainers')
show collections
db.trainers.find({name:"Ashe"})
db.trainers.findOne({name:"Ashe"})
db.trainers.update({name:"Ashe"},{$set:{level:7}})
db.trainers.update({name:"Ashe"},{name:"Ash Clown"})
const t = db.trainers
t.update({name:"Misty"},{},{upsert:true})
t.deleteMany({name:{$exists:false}})
t.deleteOne({_id:ObjectId("6073170842691fc14f93caa4")})

References

Advanced

  • Indices - make things fast
  • Aggregation Pipelines - array.reduce() for lists of documents - can also be done completely on application level (TS/JS), but DB is probably faster

pokemon-mongo-robot's People

Contributors

mkraenz avatar knoffi avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.