_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() { return new Promise((resolve, reject) => { this.mongoClient.connect((err, client) => { if (err) { return reject(err); } this.client = client; this.db = this.client.db(this.dbName); return resolve(); }); }); }
it("doesn't double escape already URI-encoded information", () => { spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(fakeClient)); new MongoStorageAdapter({ uri: 'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', }).connect(); expect(MongoClient.connect).toHaveBeenCalledWith( 'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', jasmine.any(Object) ); });
app.post('/collect', (req, res) => { console.log(req.body); const client = new MongoClient(process.env.MONGO_URL); client.connect((err) => { const db = client.db(); const collection = db.collection('events'); collection.insertOne({ timestamp: new Date(), ...req.body }, ((err, result) => { client.close(); res.send('ok'); })); }); });
MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}, (err, mconn) => { if(err) { console.error(err) process.exit(1) } torrentdb = mconn.db('torrent') torrentdb.collection('log').createIndex({date: 1, reqs: -1}) torrentdb.collection('log').createIndex({hash: 1}) torrentdb.collection('hash').createIndex({hash: 1}, {unique: 1}) torrentdb.collection('hash').find().sort({_id: -1}).limit(1).next((err, r) => { nextTorrentId = (r && r._id || 0) + 1 console.log('Next torrent _id is', nextTorrentId, 'tableCaption', process.env.TABLE_CAPTION) }) })
// Use connect method to connect to the Server setTimeout(() => { client.connect(function(err) { if (err) { return console.error(err); } console.log("Connected successfully to database"); db = client.db(MONGO_DATABASE_NAME); }); }, 2000);
async function startServer() { const client = await MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}) app.context.torrentdb = client.db('torrent') app.context.mdb = await mysql.createPool({ connectionLimit: 5, host: 'localhost', user: 'root', password: '', port: 9306, multipleStatements: true }) app.listen(process.env.PORT || 3000, async () => { console.log(new Date(), 'Server is istening...') if(process.send) { process.send('ready') } }) }
this.connectionPromise = MongoClient.connect(encodedUri, this._mongoOptions).then(client => {
MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}, (err, mconn) => { if(err) { console.error(err)
MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}, (err, mconn) => { if(err) { console.error(err)
MongoClient.connect('mongodb://localhost:27017/admin', {useNewUrlParser: true}, (err, mconn) => { if(err) { console.error(err)
this.connectionPromise = MongoClient.connect(encodedUri, this._mongoOptions) .then((client) => {
_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; }
// https://github.com/parse-community/parse-server/pull/148#issuecomment-180407057 it('preserves replica sets', () => { spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(fakeClient)); new MongoStorageAdapter({ uri: 'mongodb://test:testpass@ds056315-a0.mongolab.com:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415', }).connect(); expect(MongoClient.connect).toHaveBeenCalledWith( 'mongodb://test:testpass@ds056315-a0.mongolab.com:59325,ds059315-a1.mongolab.com:59315/testDBname?replicaSet=rs-ds059415', jasmine.any(Object) ); });
it('auto-escapes symbols in auth information', () => { spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(fakeClient)); new MongoStorageAdapter({ uri: 'mongodb://user!with@+ symbols:password!with@+ symbols@localhost:1234/parse', }).connect(); expect(MongoClient.connect).toHaveBeenCalledWith( 'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', jasmine.any(Object) ); });