Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let query = [];
- if (!lodash.isEmpty(conditions)) {
- query.push({$match: conditions});
- }
- query.push(
- {$lookup: {
- from: 'projects',
- localField: '_id',
- foreignField: 'user',
- as: 'projects'
- }},
- {$sort: {internalCode: 1}}
- );
- db.User.aggregate(query)
- .allowDiskUse(true)
- .cursor({batchSize: 1000})
- .exec()
- .eachAsync((user) => {
- writer.addRow({
- 'ID': user.internalCode,
- 'Apellido': user.lastName,
- 'Nombre/s': user.firstName,
- 'Género': {female: 'Femenino', male: 'Masculino'}[user.gender],
- 'Fecha de Nacimiento': user.birthdate,
- 'DNI': user.dni,
- 'Provincia': user.location.province,
- 'Dirección': user.location.address + ' ' + user.location.number,
- 'Piso/Departamento': (user.location.floor || '-') + ' / ' + (user.location.apartment || '-'),
- 'Email': user.email,
- 'Teléfono': user.phone,
- 'Celular': user.mobile,
- 'Proyecto': user.projects.length ? user.projects[0].name : '',
- 'Deshabilitado': user.disabled ? 'SÍ' : 'NO'
- });
- }, {parallel: 1000})
- .then(() => {
- writer.finalize();
- })
- .catch(next);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement