<-->
본문 바로가기

프로그래밍/nodeJS

(mac 전용)변경된 mongoDB 세팅 및 기본 명령어

반응형

맥에서 mongoDB 세팅하는데 많은 고생을했다. 언젠가 다시 설치할지도 몰라서 적어놓는다.

 

 

I. 맥에서 몽고디비 설치가 어려웠던 이유

 

brew install mongodb

이 명령어는 이제 사용할 수 없다.

mongoDB 라이선스문제로 Homebrew-core에서 삭제됐기 때문이다.

이제는 사용자정의 homebrew 탭(?)에서 다운받을 수 있다고한다.

(자세한내용은 아래 링크에서 확인)

출처: https://github.com/Homebrew/homebrew-core/pull/43770

 

Remove mongodb by fxcoudert · Pull Request #43770 · Homebrew/homebrew-core

To our users: if you came here because mongodb stopped working for you, we have removed it from the Homebrew core formulas since it was migrated to a non open-source license. Upstream maintains the...

github.com

 

II. 변경된 몽고디비 설치 순서

 

brew tap mongodb/brew

 

brew install mongodb-community

 

brew services start mongodb-community

 

sudo mongod --dbpath ~/db/data (데이터 디렉터리 경로 설정 및 프로세스 실행)

 

 

III. mongo shell 기본 명령어

 

데이터베이스 조회

show dbs

데이터베이스 생성 & 스위칭

 use <데이터베이스 이름>

데이터베이스 내의 모든 컬렉션 조회

show collections

 

 

IV. mongo shell CRUD 명령어

 

Create

db.<데이터베이스 이름>.insert({})

Read

db.<데이터베이스 이름>.find({});

Update

db.<데이터베이스 이름>.update({},{})
//첫번째 매개변수를 두번째 매개변수로 바꿈

Delete

db.<데이터베이스 이름>.delete({});