I have a production
and staging
environments on one machine. One rails app works the fulltime. One (actually the same) rails app is only for testing/implementing new features.
So I use a mongodb:
mongod --dbpath /path/to/my/production/rails/app/db
I would also like to run one mongod with:
mongod --dbpath /path/to/my/staging/rails/app/db
But I cannot imagine how to do that, because if I do just as described, I obviously get:
Mon Oct 14 16:12:59 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Mon Oct 14 16:12:59 [initandlisten] ERROR: addr already in use
So what is the best practice to work with two different mongodb instances on one machine to be able to work with both production and staging apps separately?
of course it is better to define different environments within the rails app (e.g. mongodb.yml) and use the same mongod process and port, but would be interesting if it is possible something like this (to compleetely separate environments):
port 27017 <--> --dbpath /path/to/my/production/rails/app/db
port 27018 <--> --dbpath /path/to/my/staging/rails/app/db
Yes.
mongod --dbpath /path/to/my/production/rails/app/db --port 12345
mongod --dbpath /path/to/my/staging/rails/app/db --port 12346
Check out this earlier answer for more information/pitfalls: multiple instances of Mongo DB on same server