Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

149
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda