Why the $divide returns null?

in my query the $divide returns null,knowing that the operands aren’t null

 Moddulle.aggregate([
      {
        $unwind: "$listEpreuves"
      },
      {
        $unwind: "$listEpreuves.resultat"
      },
      {
        $group: {
          _id: {
            nom: "$listEpreuves.resultat.nom_etudiant",
            prenom: "$listEpreuves.resultat.prenom_etudiant", 
           },
          cursus: {
            $push: {
              designation_moddulle: "$designation_moddulle",
              pv_modulaire: {
                code_epreuve: "$listEpreuves.code_epreuve",
                valeur_note: "$listEpreuves.resultat.valeur_note"
              },
              moyModule:{$multiply:[{$avg:"$listEpreuves.resultat.valeur_note"},"$coefficient"]
            }
          } },
          moyGlob:{ $avg: {
            $multiply: [
              { $avg: "$listEpreuves.resultat.valeur_note" },
              "$coefficient"
            ]
          }
        },
         sommeCoef:{$sum:"$coefficient"},
       }
    },    
      {
        $group: {
          _id: null,
          data: {
            $push: {
              nom: "$_id.nom",
              prenom: "$_id.prenom",
              mmoy:"$_id.moyenneGlobalee",
              cursus:"$cursus",
              moy:{$sum:"$cursus.moyModule"},
              someCoeff:"$sommeCoef",  
              moyenneGlobalee:{$divide: ["$moy","$someCoeff"]},  
              } } },     
         },
              {
        $project: {
          _id: 0,
          data: 1, 
         
         },},

Qu’est-ce que se passe si l’on ecrit

moyenneGlobalee:{$divide: ["$moy","$sommeCoeff"]}

( L’ordre d’évaluation)

1 Like

$sommeCoef might not be null but $someCoeff is in this stage. you cannot use a field in the same stage that is defined

1 Like

that was the problem thank you

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.