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

306
Vistas
How to get specific distinct field from mongoose?

I have db collection like this

[
{
name: "Fried Burger",
image: "https://burgerimage.com",
category: "burger"
},
{
name: "Fried Pizza",
image: "https://pizzaimage.com",
category: "pizza"
},
{
name: "Veg Pizza",
image: "https://vegpizzaimage.com",
category: "pizza"
},
{
name: "Fried Pasta",
image: "https://friedpastaimage.com",
category: "pasta"
}
]

Is there any way I get value from category without repeating and single image although there are multiple categories like this

[
{category: "burger", image:"https://burgerimage.com"},
{category: "pizza", image:"https://pizzaimage.com"}, //Any image works as long as category is same
{category: "pasta", image:"https://pastaimage.com"}

I used .distinct('category') but it only returns like this but I also want one image with that

{
  "category": [
    "Burger",
    "beef",
    "chicken",
    "duck",
    "pasta",
    "pizza",
    "pork"
  ]
}
over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

If you want just the category and image of each, try this

 MyModel.find({} , 'category image', function(err, docs) { })
over 4 years ago · Santiago Trujillo 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