MongoDB data migration

export

Go to the installation directory of mongodb\Server\3.6\bin

mongodump --host 192.168.1.2:27017 -d dbname -uuername mongo -ppasswd 123456 -o /dump
  1. --host : configure the service access address of mongodb
  2. -d: Specifies the database. Optional parameter, export all DBs without this parameter
  3. -uuername: Specify the username to connect to mongodb
  4. -ppasswd: Specify the password to connect to mongodb
  5. -o: specify the output directory

mongodb start command

$ mongod -f mongod.conf --serviceName MongoDB --install
$ net start MongoDB

mongod.conf :

systemLog:
   destination: file
   path: 'F:\Mongodb\Server\logs\mongod.log'
   logAppend: true
storage:
   journal:
      enabled: true
   dbPath: 'F:\Mongodb\Server\data'
net:
   bindIp: 0.0.0.0
   port: 27017
setParameter:
   enableLocalhostAuthBypass: false

recover

mongorestore -h hostname:port -d dbname <path>  

some important parameters

  1. -h[:port] specifies the server address where MongoDB is located, the default is localhost
  2. -d database to restore
  3. –drop When restoring, delete the current database first, and then restore the backup, operate with caution
  4. Set the location of the backup data, which conflicts with the parameters below
  5. –dir specifies the backup directory, which conflicts with the above parameters

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324843908&siteId=291194637