ccmjs / data-server

ccm-compatible NodeJS webserver for server-side data management via HTTP using MongoDB and CORS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Improvement: Mongodb connect config

opened this issue · comments

It would be nice to config the mongoDB connection. In my code I changed the connectMongoDB function like this:

mongodb.MongoClient.connect(
      `${mongo_config.local.uri}:${mongo_config.local.port}`,
      { useNewUrlParser: true },
      ( err, client ) => {
        if ( !err ) { mongodb = client.db( 'ccm' ); return callback(); }
        if ( !waited ) setTimeout( () => connectMongoDB( callback, true ), 3000 );
        else { mongodb = null; callback(); }
      });

mongo_config is a defined as const at the beginning of the document where also the config for the node server is located.

const mongo_config = {
  local: {
    uri: "mongodb://172.17.0.2",
    port: "27017"
  }
};

Could also be included in the node config object const config = { node: {...}, mongo: {...} }.

Thank's for report. That's a good idea. I have added mongodb settings in config.