I am new to mongodb. I am doing simple application that uses this database. Here is my doctors collection structure:
{
_id: 1,
name: "David",
specialisation: "dentist",
description: "Super dentist",
treatments: [
{
_id: 0,
price: 2200
},
{
_id: 2,
price: 200
},
{
_id: 5,
price: 2500
},
{
_id: 8,
price: 3200
},
{
_id: 13,
price: 2050
}
],
hospitals: [1, 2, 8, 5, 20]
},
{
_id: 2,
name: "John",
specialisation: "dentist",
description: "Super dentist",
treatments: [
{
_id: 2,
price: 2500
}
],
hospitals: [1]
}
What I want to do, is to get the max value of a treatment with specified id of all doctors in collection. For example in this case if I want to check treatment with _id = 2 it should return 2500, as it is written in John's object.
Any help would be appreciated. Thanks.
treatments:{1:"2200",2:"200",5:"2500",8:"3200",13:"2050"}then u vl be able to do like treatments[2] ortreatments:{1:{key1:val1,key2:val2},2:{key1:val1,key2:val2}}tell which approach suits you , vl help u out in that approach's codetreatment with _id = 2 it should return 2500, as it is written in John's objecthere _id=2 u mean outside _id(above name:"john") or the one inside array ?