2

I'm trying to use promised-mongo to access a MongoDB database hosted on Compose.io. I am using the same connection string I use to accept the DB using the mongo CLI tool, but when I try to connect I get:

err { [MongoError: auth failed] name: 'MongoError', message: 'auth failed', ok: 0, errmsg: 'auth failed', code: 18 }

I nosed around in the promised-mongo code a bit and it appears to be using a standard MongoDB library called MongoCR for the authentication. Is this authentication approach simply incompatible with Compose.io, or do I have to change the config of our database somehow or adapt the connection string?

Matthew Gertner
  • 4,487
  • 2
  • 32
  • 54
  • Actually this appears to be built on [mongodb-core](https://github.com/christkv/mongodb-core) ( as it is generally advised for any higher level adaptations in nodejs to do ). You might be getting confused by the difference between [MONGODB-CR and SCRAM-SHA1](https://docs.mongodb.org/v3.0/core/security-scram-sha-1/) authentication in MongoDB releases. But this is entirely dependant which version is being offered ( and/or chosen by you ) with your provider. The mongodb-core that should be installed supports both. That's what's in the dependencies list anyway. – Blakes Seven Feb 14 '16 at 11:45
  • I've haven't delved too deeply into the code, but have a look at https://github.com/gordonmleigh/promised-mongo/blob/master/lib/Database.js#L115. It seems to me like the `mongocr` auth provider is hardcoded. I'm assuming that Compose.io doesn't support this, but I don't see an obvious way to change this to use a different auth provider. – Matthew Gertner Feb 14 '16 at 12:30
  • 1
    FWIW the error seems to go away if I set `ssl: true` in the options. I'm not sure whether this is really the root cause of the issue or not. It probably isn't due to the auth mechanism since I looked more closely and a whole range of auth providers are set in the `Server` constructor of `mongodb-core` by default. In any case I still can't get `promised-mongo` to return any results from the database. I've given up and switched to `mongojs`, which seems to work fine. Pity about the promises though. – Matthew Gertner Feb 14 '16 at 13:09
  • Worth taking a look at the standard nativemongodb driver too https://github.com/gordonmleigh/promised-mongo/issues/35 that should return promises if you don't provide a callback. – RYFN Oct 11 '16 at 21:41

0 Answers0