My document structure is as follow :
{
"_id" : ObjectId("621e438004f5eb0b16ce6e34"),
"h_name" : "WWW Hospital",
"specializations" : [
"Gynaec",
"Orthopaedic"
],
"doctors" : [
{
"dr_name" : "Dr. Mehta",
"visit_day" : "Monday"
},
{
"dr_name" : "Dr. Kale",
"visit_day" : "Monday"
},
{
"dr_name" : "Dr. MK",
"visit_day" : "Tuesday"
}
],
"public_review" : [
{
"p_name" : "Ajit",
"rating" : 4
},
{
"p_name" : "Vijay",
"rating" : 2
},
{
"p_name" : "Piyush",
"rating" : 4
}
]
}
How to perform the following query
List the names of doctors who are visiting “Jehangir Hospital ” on
Mondays
I try this :
db.hospital.find({
h_name: 'WWW Hospital',
doctors: {
$elemMatch: {
visit_day: 'Monday'
}
}
}, {
_id: 0,
"doctors.dr_name": 1,
"doctors.visit_day": 1
})
Output :
{ "doctors" : [ { "dr_name" : "Dr. Mehta", "visit_day" : "Monday" }, { "dr_name" : "Dr. Kale", "visit_day" : "Monday" }, { "dr_name" : "Dr. MK", "visit_day" : "Tuesday" } ] }
The output contains an object of Dr. MK also whose visit_day is Tuesday I want to list dr_names whose visit_day is Monday