2

I am trying to connect mysql database and mongodb for my node js project. I am writing the connection pooling in separate db.js file and i am exporting. but i cant access the connection in my index.js router file.

db.js

var mysql      = require('mysql');
var mongodb =  require('mongodb');
var db;
var coll;
var MONGODB_URI = 'mongodb://localhost:27017/local'
var mongoDbConnection = mongodb.MongoClient.connect(MONGODB_URI, function(err, database) {
  if(err) throw err;
  db = database;
});
var db_config = {
          host: 'localhost',
            user: 'root',
            password: 'ram',
            database: 'test',
            multipleStatements:true
        };
var connection = mysql.createPool(db_config);
connection.getConnection(function(err, connection) {
});
module.exports = connection,mongoDbConnection ;

index.js

var express = require('express');
var connection =  require('../db');
var mongoDbConnection =  require('../db');

console.log(mongoDbConnection) but here i couldn't read mongoDbConnection parameters.

Ram
  • 93
  • 1
  • 9
  • Did you find the solution for this problem? I am also having the same issue. I need to connect to two different oracle DBs at same time... can you post me an answer if you have? –  May 16 '19 at 13:22

0 Answers0