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

153
Views
mongoDB group by nested document with unknown path

i want group by value and my problem is screen_size and screen_resulation is changeable

is there is something like wildcard in nested document in mongodb ?

i have tried this but its not working

[
    {
      filters: {
        screen_size: {
          name: "حجم الشاشة",
          value: "50",
        },
        screen_resulation: {
          name: "دقة الشاشة",
          value: "4k",
        },
      },
    },
    {
      filters: {
        screen_resulation: {
          name: "دقة الشاشة",
          value: "UHD",
        },
        screen_size: {
          name: "حجم الشاشة",
          value: "55",
        },
      },
    },
    {
      filters: {
        screen_resulation: {
          name: "دقة الشاشة",
          value: "4k",
        },
        screen_size: {
          name: "حجم الشاشة",
          value: "55",
        },
      },
    },
  ];



{
$group : {
 _id: "$filters.*.value", counter: { $sum: 1 }
}
 }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can get the desired result with the below approach as well:

[{$project: {
  _id: '$_id',
  filters: { $objectToArray: '$filters' }
}}, {$unwind: {
  path: '$filters'
}}, {$group: {
  _id: '$filters.v.value',
  count: {$sum: 1}
}}]
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!