반응형
Database
# DB 생성 및 사용
use DB명
# DB 확인
db
# DB 리스트 조회
show dbs
# DB 삭제
db.dropDatabase()
※ DB 삭제하기 전에 'use DB명' 으로 삭제할 DB에서 쿼리를 실행해야함!
Collection
# Collection 생성
# 방법1(옵션없이)
db.createCollection("컬렉션명");
#방법2(옵션과함께)
db.createCollection("컬렉션명", {
options
});
#방법3
db.컬렉션명.insert({"key":"value"});
# Collection 리스트 조회
show collections;
# Collection 삭제
db.컬렉션명.drop();
Document
# Document 추가(데이터)
# 1개의 Document
db.컬렉션명.insert({"key":"value", "key2":"value2", ...});
# 여러개의 Document
db.컬렉션명.insert([
{"key":"value", "key2":"value2", ...},
{"key":"value", "key2":"value2", ...},
...
]);
# Document 조회(전체)
db.컬렉션명.find();
# Document 삭제
db.컬렉션명.remove({"test":"1"});
# test 가 1인 Document 삭제
반응형
'mongo db' 카테고리의 다른 글
[MongoDB] update 쿼리 만들기(Aggregation) (0) | 2023.01.02 |
---|---|
[MongoDB] findOneAndUpdate 사용법 (0) | 2022.12.28 |
[Spring] Jackson 라이브러리로 데이터 필터링하기 (0) | 2022.10.19 |