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) }) })
/** * Iterate over records * * @param {*} collection * @param {*} query * @param {*} opts * @returns * @memberof MongoAdapter */ each(collection, query, opts) { const cursor = this.find(collection, query, { ...opts, cursor: true }); return { async do(fn) { while (await cursor.hasNext()) { await fn(await cursor.next()); } } }; }
const cursor = collection.find(query); while (await cursor.hasNext()) { const user = await cursor.next(); user.alerted = (user.alerted || []).reduce((alerted, [repo, tag]) => { alerted[repo] = tag;