MongoDB的导入与导出
导出
mongoexport --host 192.168.1.1 --port 27017 -d dbName -c collection -o ~/dbName
对应批处理
@echo off set host=192.168.1.1 set port=27017 set database=test set user=root set password=roar set collection=tb1 tb2 ... for %%c in (%collection%) do mongoexport --host %host% --port %port% -d %database% -c %%c -o d:/data/%%c.txt -u %user% -p %password% pause
导入
mongoimport --host 192.168.1.1 --port 27017 -d dbName -u user -p pwd -c collection --file ~/filename
对应批处理
@echo off&setlocal EnableDelayedExpansion set host=192.168.1.1 set port=27017 set database=test set user=root set password=roar set DestPath=d:\data set DestExt=.txt rem 遍历文件名 %%~na for /f "delims=" %%a in ('dir /b d:\data\*.txt') do ( rem echo %%~na mongoimport --host %host% --port %port% --d %database% -u %user% -p %password% -c %%~na --file %DestPath%/%%~na.txt ) pause