Hi Team,
I’m new to Mongo DB and using Mongo DB API for Cosmos DB.
Cosmos DB does not fully support the $lookup & Pipeline command so I have an issue with using both in a single Aggregate. So trying to avoid but I need to get the total students to count based on Site id.
have 2 collections … Class, Students. need to get the total students to count based on site id without the pipeline.
need an alternative to use that.
here below my code:
db.getCollection(classrooms).aggregate(
[
{
"$sort": {
"_id": -1
}
},
{
"$match": {
"$and": [
{
"is_deleted": 0,
"site_id": "111"
}
]
}
},
{ "$addFields": { "Class_Id": { "$toString": "$_id" }}},
{ "$lookup": {
"from":'student_collection',
"localField": "Class_Id",
"foreignField": "Class_Id",
"as": "student_data",
"pipeline":[
{"$match":{
"classrooms.site_id" : "111"
}}
],
}},
{ "$addFields": {"studentCount": { "$size": "$student_data"}}},
{
"$limit": 100
},
{
"$skip": 0
},
])
any help!!
Thank you