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) }) })
const stream = torrentdb.collection('hash').find().stream() const d = [] stream.on('error', (err) => {
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)
const stream = torrentdb.collection('log').aggregate([
async get (sid) { try { let doc = await this.coll.findOne({ sid: sid }) return doc ? doc.session : undefined } catch (e) { log(e.message) } }
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}), }); }
updateSchedule(param,schedule,options){ try{ schedule = this.checkAtomacity(schedule); this.schedules.updateOne(param, schedule,options); }catch(err){ console.error(err); } }
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; }
deleteSignup(param, options, callback){ if (!param.season){ param.season = "season 15"; } try{ this.signups.deleteOne(param, options, callback); }catch(err){ console.error(err); } }
// // 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 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; }
updatePlayer(param,player,options){ try{ player = this.checkAtomacity(player); this.players.updateOne(param, player,options); }catch(err){ console.error(err); } }
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; }