I am trying to write a query in mongoDB with an OR operation inside a list of objects and the query should return one field of that document rather than returning the complete document. Let say I have database like this
{
"PID : "PID-1",
PriceList : {
{
cityId:1,
stateId:2,
country:X,
},
{
cityId:1,
stateId:3,
country:X,
},
{
cityId:2,
stateId:2,
country:X,
}
}
},
{
"PID : "PID-2",
PriceList : {
{
cityId:1,
stateId:2,
country:X,
}
}
}
Now, If I give my input as PID = PID-1, CityId = 1, country = X. Then I should get this o/p
{
PriceList : {
{
cityId:1,
stateId:2,
country:X,
},
{
cityId:1,
stateId:3,
country:X,
}
}
}
Let's say if I give input as PID = PID-1 and country = X then o/p should be
{
{
cityId:1,
stateId:2,
country:X,
},
{
cityId:1,
stateId:3,
country:X,
},
{
cityId:2,
stateId:2,
country:X,
}
}
I tried various queries but could not solve it.