[MongoDB] collections methods

Woong·2023년 1월 31일
0

DB

목록 보기
12/16

collection 목록 조회

  • show collections

  • db.getCollectionNames()

    • db.runCommand( { listCollections: 1.0, authorizedCollections: true, nameOnly: true } ) 와 동일
  • 권한에 따라 system db 제외하기

    • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) print(db[c])})

collection 별 document 수 count

  • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) {print (db[c]); print(db[c].countDocuments())}})

collection 별 index 조회

  • getIndexes() : index 조회

    • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) {print (db[c]); print(db[c].getIndexes())}})
  • totalIndexSize(): index size 조회

    • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) {print (db[c]); print(db[c].totalIndexSize())}})

통계 정보

  • stats() : 통계 정보 조회

    • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) {print (db[c]); print(db[c].stats())}})
  • totalIndexSize() : index 가 차지하는 bytes

  • storageSize() : document storage 가 차지하는 bytes

    • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) {print (db[c]); print(db[c].storageSize())}})
  • totalSize() : index, data 합쳐서 전체 bytes

전체 collection drop 하기

  • db.getCollectionNames().forEach(function(c) { if (c.indexOf("system.") == -1) db[c].drop()})

reference

0개의 댓글