Advertisement
Guest User

Untitled

a guest
Mar 20th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. let query = [];
  2. if (!lodash.isEmpty(conditions)) {
  3. query.push({$match: conditions});
  4. }
  5. query.push(
  6. {$lookup: {
  7. from: 'projects',
  8. localField: '_id',
  9. foreignField: 'user',
  10. as: 'projects'
  11. }},
  12. {$sort: {internalCode: 1}}
  13. );
  14.  
  15. db.User.aggregate(query)
  16. .allowDiskUse(true)
  17. .cursor({batchSize: 1000})
  18. .exec()
  19. .eachAsync((user) => {
  20. writer.addRow({
  21. 'ID': user.internalCode,
  22. 'Apellido': user.lastName,
  23. 'Nombre/s': user.firstName,
  24. 'Género': {female: 'Femenino', male: 'Masculino'}[user.gender],
  25. 'Fecha de Nacimiento': user.birthdate,
  26. 'DNI': user.dni,
  27. 'Provincia': user.location.province,
  28. 'Dirección': user.location.address + ' ' + user.location.number,
  29. 'Piso/Departamento': (user.location.floor || '-') + ' / ' + (user.location.apartment || '-'),
  30. 'Email': user.email,
  31. 'Teléfono': user.phone,
  32. 'Celular': user.mobile,
  33. 'Proyecto': user.projects.length ? user.projects[0].name : '',
  34. 'Deshabilitado': user.disabled ? 'SÍ' : 'NO'
  35. });
  36. }, {parallel: 1000})
  37. .then(() => {
  38. writer.finalize();
  39. })
  40. .catch(next);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement