templates/express/util/mongo.js
// Connect to mongo and return a db object of the given database
Connect to mongo and return a db object of the given database
Connect to mongo and return a db object of the given database
async function connect(database) {
  if (connections[database]) {
    return connections[database];
  } else {
    const mongoURL = `${config.mongo.url}:${config.mongo.port}`;
    const client = new MongoClient(mongoURL, { useUnifiedTopology: true });
    await client.connect();
    connections[database] = client.db(database);
    return connections[database];
  }
}
async function connect ( database ) { if ( connections [ database ] ) { return connections [ database ] ; } else { const mongoURL = ` ${ config . mongo . url } ${ config . mongo . port } ` ; const client = new MongoClient ( mongoURL , { useUnifiedTopology : true } ) ; await client . connect ( ) ; connections [ database ] = client . db ( database ) ; return connections [ database ] ; } }
Connect to mongo and return a db object of the given database
Connect to mongo and return a db object of the given database