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'); })); }); });
_adaptiveCollection(name) { return this.connect().then(() => this.database.collection(this._collectionPrefix + name)).then(rawCollection => new _MongoCollection.default(rawCollection)).catch(err => this.handleError(err)); }
executeInCollection(name, fn) { return new Promise((resolve, reject) => { if (!this.db) { return reject( new Error( 'It seems that mongodb is not initialized, try invoking connect()' ) ); } const collection = this.db.collection(name); return fn(collection, (err, result) => { if (err) { return reject(err); } return resolve(result); }); }); }
const stream = torrentdb.collection('hash').find().stream() const d = [] stream.on('error', (err) => {
const stream = torrentdb.collection('log').aggregate([
.collection('fs.files') .count() .then(count => { .collection('fs.chunks') .count() .then(count => { .collection('fs.files') .count() .then(count => { .collection('fs.chunks') .count() .then(count => {
const stream = torrentdb.collection('log').find({date: process.env.DATE}).stream() const d = [] let ii = 0 stream.pause() console.log(ii) torrentdb.collection('hash').bulkWrite(d, (err, r) => { if(err) { console.error(err) stream.on('finish', () => { if(d.length > 0) { torrentdb.collection('hash').bulkWrite(d, (err) => { if(err) { console.error(err)
static async addEvent() { const client = await mongoClientPromise; const db = client.db(dbName); const collection = db.collection(this.collectionName); await collection.insertOne({ createdAt: new Date(), message: randomstring.generate({length: 1000}), }); }
app.get('/', async function (req, res) { MongoClient.connect(url, function (err, client) { if (err) throw err; let database = client.db(db); database.collection(collection).findOne().then(function (result) { if (result) { res.json(result); } }) }); });
mongoose.connection.db.collection('experiences', function (err, collection) { if (err) throw err; collection.find({}).toArray(function (err, experiences) { res.send(experiences) }); });
// // Data access methods for feedback documents // listFeedbackForEventTopic(eventid, topicid) { return this.db.collection(this.FEEDBACK_COLLECTION).find({$and: [{event: eventid}, {topic: topicid}]}).toArray(); }
async function insertOne(collectionname, json){ const client = new MongoClient(url, {useUnifiedTopology: true}); await client.connect(); const col = client.db("spider").collection(collectionname); const result = await col.insertOne(json); client.close(); return result; }
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; }
async function deleteOne(collectionname,json){ const client = new MongoClient(url, {useUnifiedTopology: true}); await client.connect(); const col = client.db("spider").collection(collectionname); const result = await col.deleteOne(json); client.close(); return result; }
mongoose.connection.db.collection('restaurants', function (err, collection) { if (err) throw err; collection.find({}).toArray(function (err, restaurants) { res.send(restaurants) }); });