[Mongodb] database, collection, document 생성하기
2022. 8. 10. 11:09ㆍMongoDB
database 생성
>use databaseName
// > use testdb
use를 사용하여 새로운 DB를 생성하거나, 사용할 수 있다.
사용 중인 DB 확인
>db
// > db
처음 db를 생성하면 test database를 사용한다.
database 목록 확인
>show dbs
// show dbs
mongodb는 데이터베이스 내부에 한 개 이상의 Document(=record)가 있어야 리스트에 나타난다.
database 제거
>use 삭제할 db
//db.dropDatabase()
collection 생성
>db.사용할DB.createCollection(name, [option])
// db.testdb.createCollection(”firstCollection”)
// testdb에 firstCollection이라는 collection 생성
collectin 확인
>show collections
// show collections
document 생성
>db.사용할DB.insertOne([
{”name”: “ex1”}
])
document 확인
>db.collection명.find()
// db.firstCollection.find()
document 제거
>db.firstCollection.deleteOne({”name”: “ex1”})
deleteOne - 일치하는 첫 번째 document 삭제
deleteMany - 일치하는 모든 document 삭제
'MongoDB' 카테고리의 다른 글
[MongoDB] Compass 원하는 버전 다운로드 링크 (0) | 2022.07.11 |
---|