Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

301
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!