Programming/Mongo DB

Mongo DB 기초 (with updateOne)

midnightcoder 2022. 10. 2. 04:27

Mongo DB 설치 후 실행

wsl 창에 아래와 같이 실행 

~$ sudo service mongodb start
~$ mongo
#현재 저장된 Database를 다 보여준다.
> show dbs

#그 중 test로 지정
> ues test

#test 안에 들어있는 collections 보여준다.
> show collections

#cities 안에 들어있는 요소 보기
> db.cities.find()

wsl 내의 결과

 

# "name"이 "Vancouver"인것의 "description을 "rain"으로 바꿔보자.
db.cities.updateOne({"name":"Vancouver"}, {"$set":{"description":"rain"}});

명령어 입력 후, 2번째줄의 결과와 같이 matchedCount 1개, 그리고 변경된것 modifiedCount 1개가 된것을 확인 할 수 있다.

다시 조회를 해보면, 위와 같이 description이 rain으로 변경되었다. (빨간줄 부분)