Hi, I am new to mongodb. Till now I have worked with SQL queries. I have the following 2 schemas, that should be joined and the following calculations to be done.
a {
academic_year: { type:String}
}
b {
b1: {type:Number, default:0 },
b2: {type:Number, default:0 },
b3: [{ b3_1: {type:Number, default:0 }, b3_2: {type:Number, default:0 }, b3_3: {type:Number, default:0 }
}]
b4: {type:mongoose.Schema.ObjectId,
ref: 'a'}
}
Let's suppose we have below example
a {
academic_year: "2021-2022"
_id:234lkjlk2342432
}
b {
b1:1,
b2: 2,
b3: [
{ b3_1: 5, b3_2: 4, b3_3: 4, },
{ b3_1: 1, b3_2: 4, b3_3: 2 }
{ b3_1: 5, b3_2: 1, b3_3: 2 }
]
b4: "234lkjlk2342432"
}
the result to return would bebelow where bigtotal= b1+b2+ sum of total field
c{
academic_year: "2021-2022",
b1:1,
b2: 2,
b3: [
{ b3_1: 5, b3_2: 4, b3_3: 4,total:13 },
{ b3_1: 1, b3_2: 4, b3_3: 2 ,total:7},
{ b3_1: 5, b3_2: 1, b3_3: 2,total:8 }
],
BigTotal:31,
}