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

175
Vistas
MongoDB Aggregation: Counting distinct fields from array

Need to count distinct tags on all registers in a mongodb query, using JS.

Register structure:

  {
  "_id": {
    "$oid": "62e593aed8fd9808777225e8"
  },
  "title": "“The world as we have created it is a process of our thinking. It cannot be changed without changing our thinking.”",
  "author": {
    "name": "Albert Einstein",
    "url": "https://quotes.toscrape.com/author/Albert-Einstein"
  },
  "tag": [
    "change",
    "deep-thoughts",
    "thinking",
    "world"
  ]
  }
about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

This could be useful. In addition to get the different values for the field, it returns the number of appearances:

db.collection.aggregate([
  {
    "$unwind": "$tag"
  },
  {
    "$group": {
      "_id": "$tag",
      "total": {
        "$sum": 1
      }
    }
  },
  
])

You can try here: https://mongoplayground.net/p/yXLYkJKO3Wf

about 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