Hi,
I have a schema like this
{
name : "A",
outerArr : [
{
outerId : 1,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
},
{
outerId : 2,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
},
{
outerId : 3,
innerArr : [
{
{ date: '2023-08-1', type: 'Normal'},
{ date: '2023-08-2', type: 'Normal'},
{ date: '2023-08-3', type: 'Normal'}
}
]
}
]
}
I want to find a document with inputs
name = “A” and outerId=1 and date= “2023-08-1”
Here is my query for the same
db.collection.find(
{ name: "abc", "outerArr.outerId": 1, "outerArr.innerArr.date": "2023-08-1" }
)
However, my intention is to get/retrieve only innerArr element matching date
{ date: ‘2023-08-1’, type: ‘Normal’}
But i am getting complete data since i do not have any filter or projection.
Please help in writing projection field to get only
{ date: ‘2023-08-1’, type: ‘Normal’}