Skip to content

Instantly share code, notes, and snippets.

@elyse0
Created October 20, 2021 18:42
Show Gist options
  • Select an option

  • Save elyse0/23d8b528e229d7b76d7b14d87d42db7d to your computer and use it in GitHub Desktop.

Select an option

Save elyse0/23d8b528e229d7b76d7b14d87d42db7d to your computer and use it in GitHub Desktop.
use colegio
db.alumnos.aggregate([
{$lookup: {
from: "alumnosEvalQueretaro",
localField: "clave_alu",
foreignField: "matricula",
as: "evaluacionesAlumnos"
}
},
{$match: {
$expr: {
$gt: [{$size: "$evaluacionesAlumnos"}, 0]
}
}
},
{$project: {
_id: 0,
alumno: {$concat: ["$nombre", " ", "$ap_paterno", " ", "$ap_materno"]},
clave_alu: 1,
evaluacionesAlumnos: 1
}
},
{$unwind: "$evaluacionesAlumnos"},
{$group: {
_id: {
clave_alu: "$clave_alu",
alumno: "$alumno",
anio: {$dateToString: {format: "%Y", date: "$evaluacionesAlumnos.fecha"}},
promedio: {$avg: "$evaluacionesAlumnos.calificacion"},
materias: {$sum: 1}
}
}
}
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment