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) }) })
async getSchedules(param,options,sort,limit){ let promise = this.schedules.find(param,options).sort(sort || {}); if (limit) return await promise.limit(limit).toArray(); return await promise.toArray(); }
MongoClient.connect(dbUrl, function (err, dbs) { if (err) throw err; const db = dbs.db('myblog9'); db.collection('posts') .find({ title: /React/ }) // .find() .limit(3) .project({title: 1, authors: 1}) .sort({author: 1}) .toArray(function (err, res) { if (err) throw err; console.log(res); dbs.close(); }) console.log("Database created!"); });
/** * Finds items based on the query * * @param {string} collection * @param {object} query * @param {object} opts * @param {number} opts.skip * @param {number} opts.limit * @returns * @memberof DiskAdapter */ find(collection, query, opts = {}) { let store = this.db.collection(collection); let transaction = store.find(query); if (_.isNumber(opts.skip)) { transaction = transaction.skip(opts.skip); } if (_.isNumber(opts.limit)) { transaction = transaction.limit(opts.limit); } if (opts.cursor) { return transaction; } else { return transaction.toArray(); } }
let l = new RegExp(`^(REBBL - )|(REL Rampup)|(GMAN Rampup)`, "i"); let docs = await dataService.getSchedulesChain({ "league":{"$regex":l}, "competition":{"$regex":c} }).sort({ match_uuid: -1 }).limit(20).toArray(); docs = await dataService.getSchedulesChain({ "league":{"$regex":s} }).sort({ match_uuid: -1 }).limit(20).toArray(); data.sides = docs.sort((a,b) => a.match_uuid > b.match_uuid ? -1 : 1);
switch (data.company){ case "rebbl": docs = await dataService.getSchedulesChain({ "league":{"$regex":l}, "competition":{"$regex":c} }).sort({ match_uuid: -1 }).limit(20).toArray(); docs = await dataService.getSchedulesChain({ "league":{"$regex":s} }).sort({ match_uuid: -1 }).limit(20).toArray(); data.sides = docs.sort((a,b) => a.match_uuid > b.match_uuid ? -1 : 1); l = new RegExp(`^(ReBBRL College)`, "i"); docs = await dataService.getSchedulesChain({ "league":{"$regex":l}}).sort({ match_uuid: -1 }).limit(20).toArray(); docs = await dataService.getSchedulesChain({ "league":{"$regex":s} }).sort({ match_uuid: -1 }).limit(20).toArray(); data.sides = docs.sort((a,b) => a.match_uuid > b.match_uuid ? -1 : 1);
.limit(20) .toArray() .then(resolve)