Advertisement
Guest User

Untitled

a guest
Feb 11th, 2019
441
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'use strict';
  2.  
  3. var _regenerator = require('babel-runtime/regenerator');
  4.  
  5. var _regenerator2 = _interopRequireDefault(_regenerator);
  6.  
  7. var _asyncToGenerator2 = require('babel-runtime/helpers/asyncToGenerator');
  8.  
  9. var _asyncToGenerator3 = _interopRequireDefault(_asyncToGenerator2);
  10.  
  11. var _mongodb = require('mongodb');
  12.  
  13. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  14.  
  15. var run = function () {
  16.     var _ref = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee() {
  17.         var client, db, userId, i;
  18.         return _regenerator2.default.wrap(function _callee$(_context) {
  19.             while (1) {
  20.                 switch (_context.prev = _context.next) {
  21.                     case 0:
  22.                         _context.next = 2;
  23.                         return _mongodb.MongoClient.connect('mongodb://localhost:27017/mydatabase', {
  24.                             useNewUrlParser: true
  25.                         });
  26.  
  27.                     case 2:
  28.                         client = _context.sent;
  29.                         db = client.db('mydatabase');
  30.                         userId = new _mongodb.ObjectID();
  31.                         _context.next = 7;
  32.                         return db.dropCollection('collection1');
  33.  
  34.                     case 7:
  35.                         _context.next = 9;
  36.                         return db.dropCollection('collection2');
  37.  
  38.                     case 9:
  39.                         _context.next = 11;
  40.                         return db.dropCollection('collection3');
  41.  
  42.                     case 11:
  43.                         _context.next = 13;
  44.                         return db.dropCollection('collection4');
  45.  
  46.                     case 13:
  47.                         _context.next = 15;
  48.                         return db.createCollection('collection1');
  49.  
  50.                     case 15:
  51.                         _context.next = 17;
  52.                         return db.createCollection('collection2');
  53.  
  54.                     case 17:
  55.                         _context.next = 19;
  56.                         return db.createCollection('collection3');
  57.  
  58.                     case 19:
  59.                         _context.next = 21;
  60.                         return db.createCollection('collection4');
  61.  
  62.                     case 21:
  63.                         i = 1;
  64.  
  65.                     case 22:
  66.                         if (!(i < 5)) {
  67.                             _context.next = 40;
  68.                             break;
  69.                         }
  70.  
  71.                         console.time('Parallel ' + i);
  72.                         _context.next = 26;
  73.                         return Promise.all([db.collection('collection1').find().toArray(), db.collection('collection2').find().toArray(), db.collection('collection3').find().toArray(), db.collection('collection4').find().toArray()]);
  74.  
  75.                     case 26:
  76.                         console.timeEnd('Parallel ' + i);
  77.  
  78.                         console.time('Sequential ' + i);
  79.                         _context.next = 30;
  80.                         return db.collection('collection1').find().toArray();
  81.  
  82.                     case 30:
  83.                         _context.next = 32;
  84.                         return db.collection('collection2').find().toArray();
  85.  
  86.                     case 32:
  87.                         _context.next = 34;
  88.                         return db.collection('collection3').find().toArray();
  89.  
  90.                     case 34:
  91.                         _context.next = 36;
  92.                         return db.collection('collection4').find().toArray();
  93.  
  94.                     case 36:
  95.                         console.timeEnd('Sequential ' + i);
  96.  
  97.                     case 37:
  98.                         ++i;
  99.                         _context.next = 22;
  100.                         break;
  101.  
  102.                     case 40:
  103.                     case 'end':
  104.                         return _context.stop();
  105.                 }
  106.             }
  107.         }, _callee, undefined);
  108.     }));
  109.  
  110.     return function run() {
  111.         return _ref.apply(this, arguments);
  112.     };
  113. }();
  114.  
  115. run();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement