0

I am using these instructions: https://help.compose.com/docs/connecting-to-mongodb#mongoose-node-and-compose

This is the connection string they gave me:

MONGO_URI=mongodb://*****:******@aws-us-west-2-portal.1.dblayer.com:15782,aws-us-west-2-portal.0.dblayer.com:15782/mydbname?ssl=true

This is the code I am trying:

certFileBuff = [fs.readFileSync(MONGO_CERT_PATH)]
options = {
     mongos: true,
     sslCA: certFileBuff,
     sslValidate: false,
     ssl: true
}

mongoose.connect(MONGO_URI, options)

At this point I get Authentication Failure errors:

if i remove ?ssl=true from the connection string I get the error: no mongos proxy available

Does anyone have mongoose working with compose.io recently?

d4rklit3
  • 417
  • 1
  • 5
  • 12

2 Answers2

0

If you are not using sharding in mongo set mongos to false. You can read about sharding in mongo here https://docs.mongodb.com/manual/core/sharded-cluster-query-router/

ponury-kostek
  • 7,824
  • 4
  • 23
  • 31
  • Apparently with compose.io it is required to use mongos (according to their documentation) They are telling me to switch up the mongos: true into mongo: {...vars} but I still get the same error. – d4rklit3 Feb 19 '17 at 20:52
0

As it turns out. I had a password that didn't get along with the connection string. I changed the password to something shorter and it worked. fwiw the password that didn't work was: tapasleechframegoldrabbitsauceb88 (Obviously I'm not using anymore)

What I learned: If you get a mongos proxy error its probably bad config. Make sure ssl=true is set on the connection string and ssl: true in your config.

If you get code: 18 authentication error then the password is either wrong or not formatted properly.

Here is my final working code:

const MONGO_URI = mongodb://****:*****@aws-us-west-2-portal.1.dblayer.com:15782,aws-us-west-2-portal.0.dblayer.com:15782/dbName?ssl=true


let ca, options = {}

if(MONGO_CERT_PATH) {
    try {
        ca = fs.readFileSync(encodeURI(MONGO_CERT_PATH))
        options = {
            mongos: {
                ssl: true,
                sslValidate: true,
                sslCA: [ ca ]
            }
        }
    } catch(err) {
        logger.warn('mongo ssl cert missing')
    }
}

let db = mongoose.connection
db.on('error', (e) => logger.error('connection error:', e))
db.once('open', () => {
    logger.info('db connected')
})

mongoose.connect(MONGO_URI, options)
d4rklit3
  • 417
  • 1
  • 5
  • 12