Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WEB-MAD- DE] Ana Bermúdez #231

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

Anabm90
Copy link

@Anabm90 Anabm90 commented Sep 7, 2020

He planteado todas, pero algunas no salen (de la 10 a la 14 y la 17), porque me sale object o un array vacío y no sé como hacer.

}
})
break;
case "11":
Copy link
Contributor

@ta-web-mad ta-web-mad Sep 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Primero en el find debías simplemente hacer el find a la base de datos y traer los que habían tenido trayectoria en la empresa.

db.collection('companies').find({"name": "Facebook"}, {relationships: 1, _id: 0})

En el resultado de esa query, filtrabas por los que trabajan ahora mismo, manejando la propiedad is_past

else {
        result[0].relationships.filter(value => {
       if(!value.is_past)console.log(`Worker: ${value.person.first_name} ${value.person.last_name}`);
});

}
})
break;
case "10":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solo te faltó acceder a la posición 0 del array resultante, tal que así:

case '10':
            db.collection('companies')
              .find(
                { name: 'Facebook' },
                { name: 1, 'products.name': 1, _id: 0 }
              )
              .toArray((error, result) => {
                if (error) {
                  console.log(error);
                  rl.question(`\nType enter to continue: `, (answer) => {
                    mainMenu();
                  });
                } else {
                  console.log(result[0]); <===================================
                  rl.question(`\nType enter to continue: `, (answer) => {
                    mainMenu();
                  });
                }
              });
            break;

})
break;

case "12":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Esta es exactamente igual que la anterior, aunque tocaba modificar el filter al resultado de la query para que esta vez solo dejara los que ya no trabajan, te falló el planteamiento inicial, te dejo la query corregida:

case "12":
              db.collection('companies').find({"name": "Facebook"}, {relationships: 1, _id: 0}).toArray((error, result) => {
                if (error) {
                  console.log(error);
                  rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
                } else {
                  result[0].relationships.filter(value => {
                    if(value.is_past)console.log(`ExWorker: ${value.person.first_name} ${value.person.last_name}`);
                  });
                  rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
                }
              })
            break;

}
})
break;
case "13":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En esta debías indicar en la query dentro del objeto person, nombre y apellido por separado:

db.collection('companies').find({$and: [
                {"relationships.person.first_name": "David"},
                {"relationships.person.last_name": "Ebersman"}
              ]}, {name: 1, _id: 0})

Copy link
Contributor

@ta-web-mad ta-web-mad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tanto la 14 como la 17 no las tienes correctamente planteadas, te dejo aquí la solución de ambas:

 case "14":
            db.collection('companies').find({"name": "Facebook"}, {competitions: 1, _id: 0}).toArray((error, result) => {
              if (error) {
                console.log(error);
                rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
              } else {
                console.log(result[0].competitions);
                rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
              }
            })
            break;

 case "17":
            db.collection('companies').find({}, {name: 1, offices: 1, _id: 0}).toArray((error, result) => {
              if (error) {
                console.log(error);
                rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
              } else {
                result.forEach(value => {
                  try{
                    if(value.offices[0].city == 'London')console.log(value.name);
                  }catch(e){};
                });
                rl.question(`\nType enter to continue: `, (answer) => { mainMenu() });
              }
            })
            break;

Muy buen trabajo Ana, tuvisteis poco tiempo y demasiados problemas técnicos ayer con este laboratorio y llegaste a hacer bastantes queries, enhorabuena.

Recuerda trabajar siempre dentro del directorio starter-code, a seguir así!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants