I am trying for MongoDB to filter based on below json format for serviceCountry = US. I only want to return those gfcidGlobals records and their corresponding object that reflects serviceCountry = US. All over objects can be ignored. Ideally I will return the gfcidGlobals and the corresponding details with the serviceCountry.
JSON:
[
{
"_id": {
"$oid": "648c0875a25a3a13f1e3e7cf"
},
"eventId": {
"$oid": "648c0875a25a3a13f1e3e7ce"
},
"gfcidGlobals": {
"789456489": [
{
"className": "test123",
"gfcid": "789456489",
"companyName": "ABC BRANCH",
"serviceCountry": "UNITED KINGDOM",
"kwtPolicyDueDate": {
"$date": {
"$numberLong": "1699833600000"
}
},
"kycLobOwner": "BSU",
"clientType": "BANK"
},
{
"className": "test123",
"gfcid": "789456489",
"companyName": "ABC BRANCH",
"serviceCountry": "US",
"kwtPolicyDueDate": {
"$date": {
"$numberLong": "1699833600000"
}
},
"kycLobOwner": "BSU",
"clientType": "BANK"
},
{
"className": "test123",
"gfcid": "789456489",
"companyName": "ABC BRANCH",
"serviceCountry": "GERMANY",
"kwtPolicyDueDate": {
"$date": {
"$numberLong": "1699833600000"
}
},
"kycLobOwner": "BSU",
"clientType": "BANK"
}
],
"456789412": [
{
"className": "test123",
"gfcid": "456789412",
"companyName": "FIRST BANK CORP",
"serviceCountry": "PHILIPPINES",
"kwtPolicyDueDate": {
"$date": {
"$numberLong": "1699833600000"
}
},
"kycLobOwner": "BSU",
"clientType": "NONBANK"
},
{
"className": "test123",
"gfcid": "456789412",
"companyName": "FIRST BANK CORP",
"serviceCountry": "Philippines",
"kwtPolicyDueDate": {
"$date": {
"$numberLong": "1699833600000"
}
},
"kycLobOwner": "BSU",
"clientType": "NONBANK"
}
]
}
}
]
I think you are looking for this one:
Mongo Playground