[NoSQL][MongoDB] Truncate a collection

[Question] How do I truncate a collection in MongoDB or is there such a thing?

Right now I have to delete 6 large collections all at once and I'm stopping the server, deleting the database files and then recreating the database and the collections in it. Is there a way to delete the data and leave the collection as it is? The delete operation takes very long time. I have millions of entries in the collections.

[Answer]

To truncate a collection and keep the indexes use

 db.<collection>.remove({})

 

[출처] https://stackoverflow.com/questions/16493902/truncate-a-collection

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

 

 

 

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 28440
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 28243
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 33957
1042 [AutoML][AutoKeras] [OSS] AutoKeras로 자동학습(AutoML) 하기 file 졸리운_곰 2023.07.02 210
» [NoSQL][MongoDB] Truncate a collection 졸리운_곰 2023.06.04 320
1040 [Tensorflow 2.0] 모델 저장하고 불러오기 졸리운_곰 2023.05.21 268
1039 [pytorch] Pytorch에서 학습한 모델 저장 및 불러오기 졸리운_곰 2023.05.21 295
1038 [MySQL] MySQL - 테이블 만들기 file 졸리운_곰 2023.05.13 345
1037 [R library] library(XML) # install.packages("XML") 인스톨 에러 졸리운_곰 2023.05.06 209
1036 [MySQL] MySQL Strict mode 끄기/켜기 졸리운_곰 2023.05.05 331
1035 [R 데이터 분석] Titanic: Machine Learning from Disaster (타이타닉 생존 예측) file 졸리운_곰 2023.04.29 227
1034 [R 데이터 분석] R 유명한 패키지 정리 졸리운_곰 2023.04.24 350
1033 [NoSQL] MongoDB 인증 모드 (password) 설정 졸리운_곰 2023.03.26 276
1032 [MySQL] [MySQL] 테이블 구조와 데이터 복사 (Table Structure and Data Copy) 졸리운_곰 2023.03.20 236
1031 [R 데이터 분석] Shiny : 대시보드 배포하기 file 졸리운_곰 2023.03.19 265
1030 [데이터 수집 및 전처리] (놀라운) 한글 데이터 짱! AwesomeKorean_Data file 졸리운_곰 2023.03.07 289
1029 [pytorch] Using BERT with Pytorch file 졸리운_곰 2023.03.06 218
1028 [pytorch] Full NMT model from pretrained BERT file 졸리운_곰 2023.03.06 138
1027 [기계학습][딥러닝] PyTorch Hello World 졸리운_곰 2023.02.12 239
1026 [PostgreSQL] 열을 행으로 전환 쿼리 졸리운_곰 2023.01.29 299
1025 [postgreSQL] PostgreSQL 계층형 쿼리 구현 방법 졸리운_곰 2023.01.29 279
1024 [postgreSQL] ORACLE쿼리에서 postgreSQL쿼리 변환 졸리운_곰 2023.01.29 221
1023 [postgreSQL] [PostgreSQL] stored function(stored procedures) 사용하기 졸리운_곰 2023.01.23 206
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED