Areeba Seher
Areeba Seher

Reputation: 150

How to transfer one mongodb database from one computer to another

I am using django 2.2 and mongodb as database for backend. i have inserted all data in my application.I am also using Robo3T for seeing collections of mongodb database.My database name is CIS_FYP_db. In my computer everything is going perfect but i want to transfer that project into another computer while i am transferring the project which also contains data\db file with many collections.wt files but when i am running that project in other computer it is showing me that database is blank.No data were present there and mongodb is making new database with the same name CIS_FYP_db with no collections.Please help me to solve this problem that how can i transfer my mongodb database into other computer so i can use it into my application which is already made for that database.Thanks in advance

setting.py

DATABASES = { 'default': { 'ENGINE': 'djongo', 'NAME': 'CIS_FYP_db', } }

Upvotes: 2

Views: 3482

Answers (2)

Mac
Mac

Reputation: 21

Assumption: you have setup mongoDb locally and want to migrate it to another computer.

1.Requirements:

  • mongodump
  • mongorestore

1.1.How to install?

1.2.Popular error.

  • sometime path is not set, so try this in cmd prompt: set path="C:\Program Files\MongoDB\Server\5.0\bin"

  • Note: please refactor the link according to your folder path.

2.Procedure:

Note: make sure you follow Step 1

2.1. Approach

we are going to create dump of mongodb from old pc(using mongodump), then transfer that dump to new pc, and import that dump using mongorestore.

2.2.Creation of dump in old pc(from where u want to replicate database)

  • cmd mongodump --host localhost:27017 --out ~/Desktop/mongo-migration
  • above cmd will create a dump in the mentioned path==> ~/Desktop/mongo-migration
  • just copy that folder and transfer it to new pc
  • Note: if you have created authenticated user then add these flag in above cmd and provide values --username [yourUserName] --password [yourPassword] --authenticationDatabase admin

2.3.Import of dump(created from old PC)

  • place that dump folder somewhere and execute below cmd
  • mongorestore C:/....../mongo-migration/ -u root --host 127.0.0.1:27017
  • done :)

Upvotes: 2

Akash Kukkar
Akash Kukkar

Reputation: 99

When you create a connection with mongodb then database is created automatically if not exist already. You can use mongodump command to get all the database records and mongorestore to restore your database on your new machine.

Upvotes: 1

Related Questions