Skip to content

Instantly share code, notes, and snippets.

@LeoHeo
Last active August 27, 2016 03:53
Show Gist options
  • Save LeoHeo/2724175ed4d948b934ba905cc2b8dbd4 to your computer and use it in GitHub Desktop.
Save LeoHeo/2724175ed4d948b934ba905cc2b8dbd4 to your computer and use it in GitHub Desktop.
how to install mongo db in mac & mongodb manual

Install

$ brew upgrade
$ brew install mongodb
$ sudo mkdir -p /data/db
$ whoami
username
$ sudo chown username /data/db
$ mongod

mongo-hacker

  • 실수방지 package 설치
  • 자동완성
$ npm install -g mongo-hacker

구조

RDB Mongo DB
Database Database
Table Collections
column * row Documents

강점

  • 데이터의 스키마 변경이 자유로움

명령어

$ show dbs # 데이터베이스 list
$ use name # 해당 데이터베이스 사용 없으면 새로생성 Document가 없으면 show dbs했을때 안나옴
$ db # node를 불러오는 명령어
$ db.getCollectionNames() # collections가져오기
$ db.users
$ db.users.insert({name: "name"})
$ db.users.find() # objectId는 자동 생성 Primary Key

Connect

mongoose를 사용해서 connect

$ npm install --save mongoose
// app.js
var mongoose = require("mongoose");
//mongoose.connect("mongodb://url/Database");
mongoose.connect("mongodb://localhose/node");
var db = mongoose.connection;
// 제대로 접속되었는지 확인
db.once("open", function() {
  console.log("Database is connected..");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment