[NoSQL] mongoexport & mongoimport

less than 1 minute read


MongoExport

  • Installation
  • Mongoexport
  • Mongoimport

Installation

brew tap mongodb/brew
brew install mongodb-database-tools

Mongoexport

# 방법1
mongoexport --uri="mongodb://root:1234@localhost:27017/testDB?authSource=admin&retryWrites=true&w=majority"  --collection=dept  --out=dept_from_mongo.json
# 방법2(추천)
mongoexport --uri="mongodb://root:1234@localhost:27017/testDB"  --authenticationDatabase=admin  --collection=dept  --out=dept_from_mongo.json

# 쿼리 넣어서 가져오기
mongoexport --uri="mongodb://root:1234@localhost:27017/testDB"  --authenticationDatabase=admin  --collection=dept -q='{"deptno":{"$gte":30}}'  --out=dept_from_mongo.json

Mongoimport

mongoimport --uri="mongodb://root:1234@localhost:27017/testDB" --authenticationDatabase=admin  -c=dept2 -d=testDB --file=emp_202201181218.json

ref