I have a mongo collection mimicking this java class. A student can be taught a number of subjects across campus.
class Students {
String studentName;
Map<String,List<String>> subjectsByCampus;
}
So a structure will look like this
{
_id: ObjectId("someId"),
studentName:'student1',
subjectByCampusName:{
campus1:['subject1','subject2'],
campus2: ['subject3']
},
_class: 'fqnOfTheEntity'
}
I want to find the count of subjects offered by each campus or be able to query the count of subjects offered by a specific campus. Is there a way to get it through query?
$sizeoperator, but you'll need to either enumerate eachcampus#field manually or jump through some hoops with$objectToArray. And if you're trying to figure out the data for the entire collection, the database is going to have to process every singlestudentsdocument which will not scale well at all.