_connect() { if (!this._connectionPromise) { this._connectionPromise = _mongodb.MongoClient.connect(this._databaseURI, this._mongoOptions).then(client => { this._client = client; return client.db(client.s.options.dbName); }); } return this._connectionPromise; }
mongodb.MongoClient.connect('mongodb://localhost:27017/nilestore', (err, database) => { if (err) { console.log(err) process.exit(1) } db = database app.listen(PORT, () => { console.log('Server listening in http://localhost:' + PORT) }) })
function stubMongoClientConnect({ connectionErr, err, response } = {}){ mongodb.MongoClient.connect = jest.fn((url, callback) => { const mongoDBClientMock = new MongoDBClientMock({ err, response }); return connectionErr ? callback(connectionErr) : callback(null, mongoDBClientMock); }); }
it('should connect to mongo db client trough the proper database url', () => { stubMongoClientConnect({ response: mockUser() }); baseResource.get('users'); expect(mongodb.MongoClient.connect).toHaveBeenCalledWith(DB_URL, jasmine.any(Function)); });
static connect() { return mongodb.MongoClient.connect('mongodb://isaac:123@ds157987.mlab.com:57987/codercamps-db').then((db) => { console.log('db connected'); this.db = db; }) }
// connect to db before all tests beforeAll(function (done) { _this = this; mongoat.MongoClient.connect('mongodb://localhost:27017/mongoatTest') .then(function (db) { _this.testDb = db; return db.dropDatabase(); }) .then(function () { _this.testCol = _this.testDb.collection('Person.remove'); _this.testCol.datetime(true); _this.testCol.version(true); }) .then(done); });
function startDb(callback) { mongodb.MongoClient.connect(process.env.MONGODB_URI, function (err, database) { if (err) { console.log(err); callback(err); } else { db = database; console.log("Database connection ready"); callback(); } }); }
constructor() { this.mongoClient = mongodb.MongoClient; this.ObjectID = mongodb.ObjectID; }
static async connect(connection, options = {}, name = 'default') { options = Hoek.applyToDefaults({ useNewUrlParser: true }, options); const client = await Mongodb.MongoClient.connect(connection.uri, options); MongoModels.clients[name] = client; MongoModels.dbs[name] = client.db(connection.db); return MongoModels.dbs[name]; }
mongo.MongoClient .connect('mongodb://localhost:27017/anychart_sample') .then(function(db) { console.log("Connected correctly to mongodb server."); return db; }) .catch(function(err) { console.error(err); process.exit(1); })
//express.Promise = require('bluebird'); function connectToDb() { mongodb.MongoClient.connect(uri, function (err, database) { if (err) return; client = database.db('employee'); //loadEmployees().ca; }); }
mongodb.MongoClient.connect(uri, function (error, db) { if (error) { console.log(error); return; } mydb = db.db('devopscc'); //var readStream = fs.createReadStream(fname); });
// connect to db before all tests beforeAll(function (done) { _this = this; mongoat.MongoClient.connect('mongodb://localhost:27017/mongoatTest') .then(function (db) { _this.testDb = db; return db.dropDatabase(); }) .then(function () { _this.testCol = _this.testDb.collection('Person.findAndModify'); _this.testCol.datetime(true); }) .then(done); });
_connect() { if (!this._connectionPromise) { this._connectionPromise = _mongodb.MongoClient.connect(this._databaseURI, this._mongoOptions).then(client => { this._client = client; return client.db(client.s.options.dbName); }); } return this._connectionPromise; }
// connect to db before all tests beforeAll(function (done) { _this = this; mongoat.MongoClient.connect('mongodb://localhost:27017/mongoatTest') .then(function (db) { _this.testDb = db; return db.dropDatabase(); }) .then(function () { _this.testCol = _this.testDb.collection('Person.update'); _this.testCol.datetime(true); _this.testCol.version(true); }) .then(done); });