sql >> Base de Datos >  >> NoSQL >> MongoDB

Spring Data Mongo:¿cómo obtener la matriz distinta anidada para el valor anidado?

Puede obtener distintas tecnologías (technology elementos de matriz) con esta agregación:

db.depts.aggregate( [
  {
       $unwind: "$departments.subdepts"
  },
  {
       $unwind: "$departments.subdepts.technology"
  },
  {
       $match: { "departments.subdepts.subdeptCd": "1D" }
  },
  {
       $group: { _id: "$departments.subdepts.technology.technologyCd", tech: { $first: "$departments.subdepts.technology" } }
  },
  {
      $replaceRoot: { newRoot: "$tech" }
  }
] )