Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
How to add only values of an objects from MongoDB to an array in NodeJS?

So here's an example of what my collection looks like:

https://i.stack.imgur.com/E5tES.png

When I run the command:

db.Try.find({Type: "Electronic"}, {Brand: 1, _id: 0})

My result is:

[
  { Brand: 'Apple' }
  { Brand: 'Dell' }
  { Brand: 'Samsung' }
]

I want to put the above data into a NodeJS array so that I can display it in HTML form.

When I try my output is:

[
  { Brand: 'Apple' },
  { Brand: 'Dell' },
  { Brand: 'Samsung' }
]

But expected output is:

['Apple','Dell','Samsung']

How can I get those results??

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can map the output from MongoDB:

const mongodb_output = [
  { Brand: 'Apple' },
  { Brand: 'Dell' },
  { Brand: 'Samsung' }
];

const result = mongodb_output.map(item => item.Brand);
console.log(result);

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda