2

I want to make a compound query in mongodb, which must add 1 for each true that it detects, but it is not working correctly, since it counts both the true and the false.

{ 
  _id: "resumen",
  summary: { $sum:
               { $cond: [ asistencia: false, 1, 0 ] }
  }
}

Example of my data:

   {
       _id: ObjectId(5fb8722ec775d2f89c47b00d),
       id_asesor: ObjectId(5fb72a4245494b99847d63c2),
       nombre_evento:" Reunión"persona:"Joaquin Vazquez Muños",
       inicio: 2020-11-20T06:00:00.000+00:00,
       fin_ev: 2020-11-20T07:00:00.000+00:00,
       duracion: 60,
       asistencia: false             <- this is the data to validate
}
Jose Colin
  • 23
  • 4

1 Answers1

1

Try { $cond: [ {$eq:["$asistencia", false]}, 1, 0 ] }. $cond is getting 3 parameters where first is the condition. So used $eq to check the condition

varman
  • 8,704
  • 5
  • 19
  • 53