Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async init() {
const connection = mergeDefault(
{
conString: `mongodb://127.0.0.1:27017/WumpiDB`
},
this.client.options.providers.mongodb
);
// If full connection string is provided, use that, otherwise fall back to individual parameters
const connectionString = connection.conString;
const mongoClient = await Mongo.connect(
connectionString,
mergeObjects(connection.options, { useNewUrlParser: true, useUnifiedTopology: true })
);
this.db = mongoClient.db(connection.db);
}
const h = require('../helper');
const async = require('async');
const MongoClient = require('mongodb').MongoClient;
const collections = {
World: null,
Fortune: null
};
MongoClient.connect('mongodb://tfb-database/hello_world?maxPoolSize=5', (err, db) => {
// do nothing if there is err connecting to db
collections.World = db.collection('world');
collections.Fortune = db.collection('fortune');
});
const mongodbRandomWorld = (callback) => {
collections.World.findOne({
id: h.randomTfbNumber()
}, (err, world) => {
world._id = undefined; // remove _id from query response
callback(err, world);
});
};
.then(() => {
return MongoClient.connect(databaseURI)
.then(client => {
const database = client.db(client.s.options.dbName);
// Verify the existance of the fs.files document
return database
.collection('fs.files')
.count()
.then(count => {
expect(count).toEqual(0);
return { database, client };
});
})
.then(({ database, client }) => {
// Verify the existance of the fs.files document
return database
.collection('fs.chunks')
.count()
export function getMongoClient () {
const url = config.get('mongo:url')
return MongoClient.connect(encodeMongoURI(url), { useNewUrlParser: true })
}
return new Promise((resolve, reject) => {
const connectionString =
typeof connectionObject === "string"
? connectionObject
: connectionObject.connectionString;
const options =
typeof connectionObject === "string"
? {}
: R.omit(["connectionString"], connectionObject);
let hasConnection = R.pick([connectionString], connectionPool);
if (R.keys(hasConnection).length !== 0) {
resolve(connectionPool[connectionString]);
} else {
MongoClient.connect(connectionString, options, (err, db) => {
if (err) {
reject(err);
} else {
connectionPool[connectionString] = db;
resolve(db);
}
});
}
});
}
connect: function() {
MongoClient.connect('mongodb://127.0.0.1:27017/ariadneIO', function(err, db) {
if(err) console.log(err);
console.log("Connected successfully to mongodb");
mongo.db = db;
mongo.collection = db.collection('data');
});
}
};
this._connection = new Promise(function(resolve, reject) {
MongoClient.connect(infos, function(err, db) {
if (err) {
reject(err);
} else {
that.db = db;
resolve();
}
});
});
}
const createClientFor = url =>
MongoClient.connect(url, { useNewUrlParser: true })
} else if (req.query.state) {
res.send("Query parameter <code>code</code> is required!");
} else {
res.send("Query parameters <code>code</code> and <code>state</code> are required!");
}
} else {
res.send("Query parameters <code>code</code> and <code>state</code> are required!");
}
});
app.listen(process.env.PORT || 8080, function() {
logger.info("WEBSITE READY FOR ACTION!");
});
}
const MongoClient = require("mongodb").MongoClient;
MongoClient.connect(process.env.MONGODB_URI, { useNewUrlParser: true }, function(error, dbClient) {
if (error) {
logger.error(error);
} else {
logger.info("CONNECTED TO DATABASE FROM WEBSITE!");
const db = dbClient.db("lyrebird");
connected(db);
}
});