I am working on a query to find the subject title, subject type, and credit value of subject with highest credit value. This is the query I have come up with:
db.Subject.aggregate([{$match:{"subject.credit":{$max:true}},
{$project:{"subject.subTitle":1, "subject.type":1, "subject.credit":1, _id: 0}}
]).pretty()
This doesn't seem to net anything. and
db.Subject.aggregate([{$match:{"subject.credit":$max}},
$project:{"subject.subTitle":1, "subject.type":1, "subject.credit":1, _id: 0}}
]).pretty()
This nets and error as shown below:
E QUERY [js] ReferenceError: $max is not defined :
@(shell):1:32
Here is a part of the database that contains the highest credit value:
db.Subject.insert(
{
"_id":ObjectId(),
"subject":{
"subCode":"CSCI321",
"subTitle":"Final Year Project",
"credit":6,
"type":"Core",
"assessments": [
{ "assessNum": 1,
"weight":30,
"assessType":"Presentation",
"description":"Prototype demonstration" },
{ "assignNum": 2,
"weight":70,
"assessType":"Implementation and Presentation",
"description":"Final product Presentation and assessment of product implementation by panel of project supervisors" }
]
}
}
)