This forum has moved, please join us on github discussions. We will keep these old posts available for reference. Thank you!

Define the uri of mongo for a remote connection

Hi,
I search to install Apostrophe 2 on a server and I have a mongo database installed on a remote server. When I launch the command:
node app.js apostrophe-users:add admin admin, the error is:

ERROR: There was an issue connecting to the database. Is it running?
Error while constructing the apostrophe-db module
MongoError: failed to connect to server [localhost:27017] on first connect

It’s mandatory to have mongo on the same server ?
I copy the local.example.je in local.js and I change the uri string in:
uri: ‘mongodb://myremoteserver:27017/apostrophe-sandbox’

But the problem is the same,
Thanks for your help,
Franck

To set the DB in new location in in path project/data/local.js . Your local.js file must have this structure

module.exports = {
  modules: {
    'apostrophe-db': {
      uri: 'mongodb://myremoteserver:27017/apostrophe-sandbox'
    }
  }
};

Thanks,
Happy New Year with A2
:slight_smile:

Thanks to ddmalliaros for the correct answer. In addition, we have removed local.example.js from the sandbox project, it was an ancient 0.5 file and just created confusion by not being right for 2.x.

In 2.x, the contents of data/local.js are merged (via _.assign) with the object you pass to configure Apostrophe in app.js.