async deleteFile(filename: string) { const bucket = await this._getBucket(); const documents = await bucket.find({ filename }).toArray(); if (documents.length === 0) { throw new Error('FileNotFound'); } return Promise.all( documents.map((doc) => { return bucket.delete(doc._id); }) ); }
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'); });
const files = await bucket.find({ filename }).toArray();
async getMetadata(filename) { const bucket = await this._getBucket(); const files = await bucket.find({ filename }).toArray(); if (files.length === 0) { return {}; } const { metadata } = files[0]; return { metadata }; }
async function find(collectionname,json) { const client = new MongoClient(url, {useUnifiedTopology: true}); await client.connect(); const col = client.db("spider").collection(collectionname); const result = await col.find(json).toArray(); client.close(); return result; }
mongoose.connection.db.collection('experiences', function (err, collection) { if (err) throw err; collection.find({}).toArray(function (err, experiences) { res.send(experiences) }); });
runQueryOrThrowAuthError(async () => { const config = Config.get(); const query = { user_id: userId }; let result = await mongoClient .collection(config.mongo.collections.refreshTokens) .find(query) .toArray(); return result.map(y => y.session_handle.toString()); })
findAll(col, search, callback) { if (search._id) search._id = new mongodb.ObjectId(search._id); this.reconnect(()=> { this.DB.collection(col).find(search).toArray((err, docs) => { if (err) { console.log(err); } callback(docs); }); }); }
// // Data access methods for feedback documents // listFeedbackForEventTopic(eventid, topicid) { return this.db.collection(this.FEEDBACK_COLLECTION).find({$and: [{event: eventid}, {topic: topicid}]}).toArray(); }
app.get("/data", async (req, res) => { const mongo = await connectMongo(); const x = await mongo .db("game-sales-demo") .collection("games") .find({}) .toArray(); res.send(x); });
db.collection(tableName).find().sort({'id': 1}).toArray(function(err, result) { if(result == [] || result == ''){ res.send('Sorry table not found in database'); } else{ output.contents = result; res.send(output); } });
async deleteFile(filename) { const bucket = await this._getBucket(); const documents = await bucket.find({ filename }).toArray(); if (documents.length === 0) { throw new Error('FileNotFound'); } return Promise.all(documents.map(doc => { return bucket.delete(doc._id); })); }
async getMetadata(filename) { const bucket = await this._getBucket(); const files = await bucket.find({ filename }).toArray(); if (files.length === 0) { return {}; } const { metadata } = files[0]; return { metadata }; }
async handleFileStream(filename: string, req, res, contentType) { const bucket = await this._getBucket(); const files = await bucket.find({ filename }).toArray(); if (files.length === 0) { throw new Error('FileNotFound');
mongoose.connection.db.collection('restaurants', function (err, collection) { if (err) throw err; collection.find({}).toArray(function (err, restaurants) { res.send(restaurants) }); });