Import more than 1 json file using mongoimport

前端 未结 12 1429
猫巷女王i
猫巷女王i 2020-11-30 00:27

I am new to mongodb and want to know about importing a json file from one server to another. I tried the following command mongoimport -d tes

12条回答
  •  旧巷少年郎
    2020-11-30 00:42

    I used the solutions here to add a shell function to my bash profile for doing this quickly.

    My example depends on the mongo export outputting each collection as a file with the collection name and .metadata.json extension.

    function mimport() { for filename in *; do collection="${filename%.metadata.json}"; mongoimport --db $1 --collection $collection --file $filename; done }

    Use in the path of the export files, passing the DB name to the command...

    mimport my_db

    Will load all collections into the DB at localhost.

提交回复
热议问题