Just show me the code

If any of you have struggled to connect Mongoose to a database other than the system admin database when using IBM Compose.io, you’re struggles are now over :-)

Here’s the secret sauce:

In order to connect to a custom db with mongoose IBM Compose, you must provide a different connection string than the default provided by Compose.

The following connection string template works:

var connectionUrl = 'mongodb://<username>:<password>@<hostname>:<port>,<hostname-n>:<port-n>/<db-name>?ssl=true&authSource=admin';

Notice that <db-name> is the name of your db and authSource, the admin db, is specified as such using a query parameter.

Note: Compose authenticates users at the admin db, thus if not specified as the db, it must be specified as the auth source

You will also need the following options:

var sslCA = [fs.readFileSync('mongo.cert')];

var options = {

ssl: true,

sslValidate: true,

sslCA,

};

I’ve provided the full source code at https://github.com/cdimascio/mongoose-compose-example

Hope this helps to alleviate some pain.