IBM-Cloud / insurance-bot

A message based insurance experience
http://cloudco.mybluemix.net
Other
36 stars 57 forks source link

Retrieve MongoDB connection from VCAP_SERVICES for proper integration with Bluemix #97

Closed l2fprod closed 8 years ago

l2fprod commented 8 years ago

@rvennam

The MongoDB database storing the logs will be bound to the dashboard app.

Here is how I'm loading it in the insurance-bot for Compose-for-mongodb: https://github.com/IBM-Bluemix/insurance-bot/blob/new-toolchain/app.js#L51

var mongoDbCredentials = appEnv.getServiceCreds("insurance-bot-db") || appEnv.services["compose-for-mongodb"][0].credentials;
if (mongoDbCredentials) {
  var ca = [new Buffer(mongoDbCredentials.ca_certificate_base64, 'base64')];
  mongoDbUrl = mongoDbCredentials.uri;
  mongoDbOptions = {
    mongos: {
      ssl: true,
      sslValidate: true,
      sslCA: ca,
      poolSize: 1,
      reconnectTries: 1
    }
  };

It tries by name but also by label - as in the toolchain the database service will have different names whether it is dev or the prod.

rvennam commented 8 years ago

The dev instance service name is dev-insurance-bot-db.

rvennam commented 8 years ago

Dashboard mongo work is done