Database/mongoDB
컬렉션 이름 조회시 필터링해서 가져오기
데브포유
2019. 7. 11. 14:04
반응형
db.getCollectionName( ) 함수를 통해서 컬렉션명을 조회할 수 있습니다.
특정 문자열로 시작하거나, 종료되거나, 포함된 컬렉션을 조회하는 방법입니다.
1. "tb_" 로 시작하는 컬렉션명을 조회하는 방법
db.getCollectionNames().filter(function (c) { return c.indexOf('tb_') == 0; })
db.getCollectionNames().filter(function (c) { return c.startWith('tb_'); })
2. "_2018" 로 끝나는 컬렉션명을 조회하는 방법
db.getCollectionNames().filter(function (c) { return c.endsWith('_2018'); })
3. "order" 가 포함된 컬렉션명을 조회하는 방법
db.getCollectionNames().filter(function (c) { return c.includes('order'); })
반응형