Moving MongoDB's data folder?

2020-06-08 02:35发布

问题:

I have 2 computers in different places (so it's impossible to use the same wifi network). One contains about 50GBs of data (MongoDB files) that I want to move to the second one which has much more computation power for analysis. But how can I make MongoDB on the second machine recognize that folder?

回答1:

When you start mongodprocess you provide an argument to it --dbpath /directory which is how it knows where the data folder is.

All you need to do is:

  1. stop the mongod process on the old computer. wait till it exits.
  2. copy the entire /data/db directory to the new computer
  3. start mongod process on the new computer giving it --dbpath /newdirectory argument.

The mongod on the new machine will use the folder you indicate with --dbpath. There is no need to "recognize" as there is nothing machine specific in that folder, it's just data.



回答2:

quite easy for windows, just move the data folder to the target location run cmd "C:\your\mongodb\bin-path\mongod.exe" --dbpath="c:\what\ever\path\data\db"



回答3:

Maybe what you didn't do was export or dump the database. Databases aren't portable therefore must be exported or created as a dumpfile.

Here is another question where the answer is further explained



标签: mongodb