Search code examples
node.jsmongodbsails.jsibm-cloud

How to connect a project with different versions of MongoDB in different environments (localhost and Bluemix)


I want to set connect to "local mongodb" when I run my sails projects on my localhost and set connect to "MongoDB experimental" on Bluemix


Solution

  • In general you can have a config.js,

    var dbconfig = {
            dev: "mongodb://localhost/mean-todo",
            prod: process.env.MONGOLAB_URI
    }
    

    connect using,

    mongoRemote: {
        adapter: 'sails-mongo',
        url: dbconfig.prod || dbconfig.dev
      },
    

    Hope this works!!