미니옵빠의 code stubs

mongoexport 관련 Tips 본문

Database/MongoDB

mongoexport 관련 Tips

미니옵빠 2019. 1. 19. 16:50

MongoDB 사용 시, 데이터 추출을 위해 mongoexport 를 활용


1. aggregate 사용하지 못함

가장 기본적인 export 도구이기 때문. 이럴 땐 aggregate 의 $out 기능을 활용하여

"집계 결과를 신규 컬렉션에 저장" > "해당 컬렉션을 mongoexport" 로 추출 이라는 절차로 진행

2.6+ 이상에서만 가능


Ref: https://stackoverflow.com/questions/16468602/mongoexport-aggregate-export-to-a-csv-file 


2. ID/PW 입력 시 특수문자 escaping

uri 나 host+id+pw 조합에서, 비밀번호 등에 @, $, single quote 등이 있을 경우 "server returned error on SASL authentication step: Authentication failed." 메시지를 뿌림

이 때 특수 문자는 escaping 해주어야 하며, 규칙은 해당 문자를 single quote 로 감싸는 것임.

추가로, "@" 문자는 uri 에 사용할 경우 Connection String URI Format 과 겹치므로 %40으로 따로 encoding 해야 함.


예) 비밀번호는 pw@3$임. @ 를 %40으로 인코딩하고, 그걸 다시 single quote 로 감싸는 형태

--uri=mongodb://id:pw'%40'3'$'@1.1.1.1:1111,


Ref: https://newbiedba.wordpress.com/2016/11/21/mongodb-3-2-server-returned-error-on-sasl-authentication-step-authentication-failed/