disconnect() { if (this.client) { this.client.close(); } }
deleteFile(filename) { return this._connect().then(database => { const gridStore = new _mongodb.GridStore(database, filename, 'r'); return gridStore.open(); }).then(gridStore => { return gridStore.unlink(); }).then(gridStore => { return gridStore.close(); }); }
handleShutdown() { if (!this._client) { return Promise.resolve(); } return this._client.close(false); }
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) ); });
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'); })); }); });
beforeEach(async () => { const gsAdapter = new GridStoreAdapter(databaseURI); const db = await gsAdapter._connect(); await db.dropDatabase(); });
it('properly overrides files', async () => { const gfsAdapter = new GridFSBucketAdapter(databaseURI); await gfsAdapter.createFile('myFileName', 'a simple file'); await gfsAdapter.createFile('myFileName', 'an overrided simple file'); const data = await gfsAdapter.getFileData('myFileName'); expect(data.toString('utf8')).toBe('an overrided simple file'); const bucket = await gfsAdapter._getBucket(); const documents = await bucket.find({ filename: 'myFileName' }).toArray(); expect(documents.length).toBe(2); await gfsAdapter.deleteFile('myFileName'); await expectMissingFile(gfsAdapter, 'myFileName'); });
// For a given config object, filename, and data, store a file // Returns a promise createFile(filename, data) { return this._connect().then(database => { const gridStore = new _mongodb.GridStore(database, filename, 'w'); return gridStore.open(); }).then(gridStore => { return gridStore.write(data); }).then(gridStore => { return gridStore.close(); }); }
handleShutdown() { if (!this._client) { return Promise.resolve(); } return this._client.close(false); }
handleShutdown() { if (!this._client) { return Promise.resolve(); } return this._client.close(false); }