问题:
使用bat脚本以json格式导出mongo数据库中指定表数据,简单记录一下。
解决:
@echo on
set mongo_bin=D:/MongoDB/Server/4.2/bin
set db=A2DB_S_PID
set tableStand=_Standard_List
set table=_S_10b450c8-325b-43ba-8a1d-623d9bedbb82
set ip=10.0.0.16
set port=27700
set /a port1=%port%+1
set /a port2=%port%+2
set username=admin
set password=5382DF4748760FA5ABD91213B1EF4621E7DD8002333121170912B42922823FEE
set outPath=D:/A2DB_S_PID
cd /d %mongo_bin%
mongoexport --host "A2DB/%ip%:%port%,%ip%:%port1%,%ip%:%port2%" --authenticationDatabase admin -u %username% -p %password% --collection %tableStand% --db %db% --out %outPath%/%tableStand%.json
mongoexport --host "A2DB/%ip%:%port%,%ip%:%port1%,%ip%:%port2%" --authenticationDatabase admin -u %username% -p %password% --collection %table% --db %db% --out %outPath%/%table%.json
echo OK!!!