Sample Header Ad - 728x90

How can I query matching MongoDB documents and return a subset of fields from an array of embedded documents?

1 vote
2 answers
4735 views
I have documents similar to the following: db.etudiants.insert( { nom:'emile', prenom:'zola', cours_reussis:[ { intitule: ['PAI'], Periodes: NumberInt(60), note: 60, date_reussite: NumberInt(2014), dispense: true, nom_ecole:'EPFC' }, { intitule:'TGP', Periodes: NumberInt(40), note:75, date_reussite: NumberInt(2013), dispense: true, nom_ecole: 'HEB' }, { intitule: 'SO2', Periodes: NumberInt(60), note: 70, date_reussite: NumberInt(2015), dispense: true, nom_ecole: 'ISFCE' }, { intitule: 'IBD', Periodes: NumberInt(60), note: 80, date_reussite: NumberInt(2015), dispense:true, nom_ecole:'ISFCE' } ] } ) How can query matching documents and return nom_ecole: 'ISFCE' and year (date_reussite) from the cours_reussis array?
Asked by zouhair (113 rep)
Dec 5, 2016, 11:14 PM
Last activity: Jul 9, 2025, 03:07 AM