mongoose.connection.once('open', function() { util.log(' > Mongo connection established.');
mongoose.connection .once('open', function () { console.log('MongoDB running'); }) .on('error', function (err) { console.log(err); });
before((done) => { mongoose.connect('mongodb://mongo:27017/users_test'); mongoose.connection .once('open', () => { done(); }) .on('error', (error) => { console.warn('Some error', error); }); });
app.listen(port, () => { console.log('MongoDB URL in use: ' + process.env.MONGO_URL) mongoose.connect(process.env.MONGO_URL) mongoose.connection .once('open', () => console.log('connected to MongoDB!')) .on('error', err => console.error('connecting to MongoDB ' + err)) console.log('Express server listening on port ' + port) })
conn.once('open', () => { // Init stream gfs = Grid(conn.db); gfs.collection(collectionName); });
before((done) => { mongoose.connection .once('open', () => { done(); } ) .on('error', (error) => { console.warn('Warning', error); }); });
var db = function(){ return { config: function(conf){ mongoose.connect('mongodb://localhost/tekbooks'); var db = mongoose.connection; db.on('error', console.error.bind(console, 'Connection error')); db.once('open', function(){ console.log('db connection open'); }); } }; }
db.once('open', async () => { global.logger.debug('connected to db success: ' + dbConnectionUrl) // init global models global.DB_MODELS = await Model.find({}) .sort({ order: 1 }) .lean() await require('./framework/models') // start server await startServer() })
static connect (): Mongoose.Connection { if(this.mongooseInstance) return this.mongooseInstance; this.mongooseConnection = Mongoose.connection; this.mongooseConnection.once("open", () => { console.log("Conectado ao mongodb."); }); this.mongooseInstance = Mongoose.connect(Constants.DB_CONNECTION_STRING); return this.mongooseInstance; }
function connect() { mongoose.connect(dbUrl, { server: { auto_reconnect: true } }); mongoose.connection.on('error', err => logger.error({ type: 'MongoDB', message: err.message })); mongoose.connection.once('connected', () => logger.info({ type: 'MongoDB', message: 'Mongo connected' })); mongoose.connection.on('disconnected', () => logger.info({ type: 'MongoDB', message: 'Mongo disconnected' })); mongoose.connection.on('reconnected', () => logger.info({ type: 'MongoDB', message: 'Mongo reconnected' })); }
db.once('open', function () { // we're connected! console.log('Database connected'); require('./user.model'); });
function connectToMongoDB(cb) { var mongoDB = mongoose.connection; mongoose.connect('mongodb://localhost/test'); mongoDB.on('error', function cb() { console.log('Error when connecting to db '); }); mongoDB.once('open', function cb() { console.log('Successfully connected to database '); }); return cb(null, mongoDB); }
connection.once('open', (err) => { if(err){ console.log('Database connection failure'); }else{ console.log('Database opened'); } });
db.once('open', () => { console.log( `You have successfully connected to your mongo database: ${MONGO_URL}` ) })
before((done) => { mongoose.connect('mongodb://localhost:27017/user_test', {useNewUrlParser: true, useUnifiedTopology: true}); mongoose.connection .once('open', () => { done(); }) .on('error', (error) => { console.warn('Warning', error); }); });