suppose I have some data in MongoDB like -
[
{
_id: new ObjectId("63608e3c3b74ed27b5bdf6fa"),
latitude: 24.3065,
hotels: [
{
name: "Saunders Oconnor",
latitude: 22.05869172633478,
longitude: 88.661309245504,
},
{
name: "Saunders Oconnor",
latitude: 22.05869172633478,
longitude: 88.661309245504,
},
],
},
{
_id: new ObjectId("63608e3c3b74ed27b5bdf6fa"),
latitude: 24.3065,
hotels: [
{
name: "Saunders Oconnor",
latitude: 22.05869172633478,
longitude: 88.661309245504,
},
{
name: "Saunders Oconnor",
latitude: 22.05869172633478,
longitude: 88.661309245504,
},
],
}
];
How can I read only a field that match my hotel name.
I am trying this-
const hotel = await places.find({ name: placeName }).project({ hotels: 1 }).toArray();
It returns me an array. like -
[
{
_id: new ObjectId("63608e3c3b74ed27b5bdf6f8"),
hotels: [ [Object], [Object], [Object], [Object], [Object] ]
}
]
But I don't want this. How can I read only a field that matches the hotel name? like -
{
name: "Saunders Oconnor",
latitude: 22.05869172633478,
longitude: 88.661309245504,
}