Created
March 21, 2020 19:35
-
-
Save sahilkashyap64/64fbf084509f3121b48435577d68f37c to your computer and use it in GitHub Desktop.
Find the number of object present in array of mongoDB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Allstudentsaag = await Attendance.aggregate( | |
[ { $match : { "subject" : "chem" } } , | |
{ $project : { _id: 0,email:1, professorclass : 1 , | |
numberofstudent: { $cond: { if: { $isArray: "$professorclass" }, | |
then: { $size: "$professorclass" }, else: "NA"} }}},]); | |
//In attendance collection Find the subject=chem ,only show email and professorclass field | |
if professorclass is an array then show the size of the array if it's empty so N/A. | |
Show the size in a fieldname called numberofstudent | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment