공부/MongoDB

[MongoDB] 데이터 삽입 및 조회

happyst 2022. 1. 2. 22:37

1. mongo.exe 실행

show dbs : 존재하는 database를 조회

use databaseName : database에 connect하는 명령어. shop이라는 database가 없더라도 data를 insert하는 순간부터 shop 이라는 database가 생성됨

 

db.collectionName.insertOne( ) : 현재 연결된 db의 collectionName에 1개의 document를 삽입

document 삽입 시 key값에는 " "를 생략해도 됨

db.collectionName.find( ) : collectionName의 데이터 조회

 

db.collectionName.find( ).pretty( ) : collectionName의 데이터를 예쁘게 조회하는 명령어. 시각화해서 보기 좋음👀

 

MongoDB가 schemaless하다는 것을 확인할 수 있다