MongoDB Bulk import using mongoimport from Windows folder

自古美人都是妖i 提交于 2019-12-20 09:41:40

问题


I have a lot of json files in archive and i need to import them into mongo per one operation (i think that it might be in cycle). Have you any ideas about this?


回答1:


If you are in a Linux/Unix shell you can try

for filename in *; do mongoimport -d mydb -c $filename;  done

If you are on Windows:

FOR %i IN (C:\mongodbData\*.json) DO mongoimport --db dbName --collection colection --type json --file %i



回答2:


mongorestore is import all exported mongodb files

cd C:\Program Files\MongoDB\Server\4.0\bin
mongorestore.exe -d <db name> C:\Users\Mike\Downloads\myProject\

But if you really want to import all only meta json files without .bson

cd C:\Users\Mike\Downloads\myProject\
FOR %i IN (*.json) DO "C:\Program Files\MongoDB\Server\4.0\bin\mongoimport.exe" --db <db name> --collection %~ni --type json --file %i

This is sample work on windows 10




回答3:


You need to use mongorestore for recovery from dump, created by the mongoexport

http://docs.mongodb.org/v2.6/reference/program/mongorestore/

for example

mongorestore --drop --oplogReplay mongodb/




回答4:


You can use this:

FOR %i IN (<data folder>\*.json) DO mongoimport -d <database> -c <collection> --file %i


来源:https://stackoverflow.com/questions/22167237/mongodb-bulk-import-using-mongoimport-from-windows-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!