MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Spring Data Mongo - Come ottenere l'array distinto nidificato per il valore nidificato?

Puoi ottenere tecnologie distinte (technology elementi dell'array) con questa aggregazione:

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" }
  }
] )