0

Hello guys I'm trying to find a way to move my mongo database inside vagrant outside of it. I'm reading some posts in this forum but they're related to postgres and mysql.

When I run npm start this is the code I have in my package.json

"start": "MONGODB=mongodb://localhost:27017....

So the problem is that the databse will get saved in Virtual Machine localhost, so, by the time it runs it won't be accessible outside of VM. How can I change this localhost path to communicate outside?

Defoe
  • 371
  • 1
  • 5
  • 17

2 Answers2

0

It is not different wether it is vagrant or another server.

The db location files are specified in /etc/mongodb.conf. By default db are saved in /data/db

So the problem is that the databse will get saved in Virtual Machine localhost, so, by the time it runs it won't be accessible outside of VM. How can I change this localhost path to communicate outside?

If you want the db to be accessible from your host machine you need to replace localhost by the IP of the vagrant VM (if you specified a private IP) or better use the 0.0.0.0 so its accessible from all network interfaces

Frederic Henri
  • 51,761
  • 10
  • 113
  • 139
0

I did it, this link gave me the answer: Vagrant reverse port forwarding?

It seems that by default mongo will be located in 10.0.2.2 outside of vagrant, so if I run inside vagrant: mongo 10.0.2.2:27017 it connects to my databases outside of vagrant.

Therefore, this is what I need to put in my package.json to run npm start...

"start": "MONGODB=mongodb://10.0.2.2:27017/
Community
  • 1
  • 1
Defoe
  • 371
  • 1
  • 5
  • 17