Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 'use strict';
- var _regenerator = require('babel-runtime/regenerator');
- var _regenerator2 = _interopRequireDefault(_regenerator);
- var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
- var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
- var _mongodb = require('mongodb');
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
- var run = function () {
- var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
- var client, db, userId, i;
- return _regenerator2.default.wrap(function _callee$(_context) {
- while (1) {
- switch (_context.prev = _context.next) {
- case 0:
- _context.next = 2;
- return _mongodb.MongoClient.connect('mongodb://localhost:27017/mydatabase', {
- useNewUrlParser: true
- });
- case 2:
- client = _context.sent;
- db = client.db('mydatabase');
- userId = new _mongodb.ObjectID();
- _context.next = 7;
- return db.dropCollection('collection1');
- case 7:
- _context.next = 9;
- return db.dropCollection('collection2');
- case 9:
- _context.next = 11;
- return db.dropCollection('collection3');
- case 11:
- _context.next = 13;
- return db.dropCollection('collection4');
- case 13:
- _context.next = 15;
- return db.createCollection('collection1');
- case 15:
- _context.next = 17;
- return db.createCollection('collection2');
- case 17:
- _context.next = 19;
- return db.createCollection('collection3');
- case 19:
- _context.next = 21;
- return db.createCollection('collection4');
- case 21:
- i = 1;
- case 22:
- if (!(i < 5)) {
- _context.next = 40;
- break;
- }
- console.time('Parallel ' + i);
- _context.next = 26;
- return Promise.all([db.collection('collection1').find().toArray(), db.collection('collection2').find().toArray(), db.collection('collection3').find().toArray(), db.collection('collection4').find().toArray()]);
- case 26:
- console.timeEnd('Parallel ' + i);
- console.time('Sequential ' + i);
- _context.next = 30;
- return db.collection('collection1').find().toArray();
- case 30:
- _context.next = 32;
- return db.collection('collection2').find().toArray();
- case 32:
- _context.next = 34;
- return db.collection('collection3').find().toArray();
- case 34:
- _context.next = 36;
- return db.collection('collection4').find().toArray();
- case 36:
- console.timeEnd('Sequential ' + i);
- case 37:
- ++i;
- _context.next = 22;
- break;
- case 40:
- case 'end':
- return _context.stop();
- }
- }
- }, _callee, undefined);
- }));
- return function run() {
- return _ref.apply(this, arguments);
- };
- }();
- run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement