I'm working on a mobile based API project. Now I'm stuck with this serious but simple issue.
How can I get show only (only true array from embedded document) "flat_tenants.is_active" : "true"
array instead of "flat_tenants.is_active" : "false"
array
{
"_id": "55eab3ff358c513439c3ce5e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eab3cb358c513439c3ce5d",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "200",
"flat_floor": "First Floor",
"flat_type": "PG",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": [
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "false",
"_id": "55eac5db5e1ddb87104a7865",
"rent": []
},
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "true",
"_id": "55eac6065e1ddb87104a7866",
"rent": []
},
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "false",
"_id": "55ead263232fe9585a86bb7f",
"rent": []
},
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "true",
"_id": "55eb434f1d844381555c41c0",
"rent": []
}
]
},
{
"_id": "55ead22e232fe9585a86bb7e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eaf552b60c9f170fbe956e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eaf5b57eda5bcc155ee42c",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
}
I want the result as
{
"_id": "55eab3ff358c513439c3ce5e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eab3cb358c513439c3ce5d",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "200",
"flat_floor": "First Floor",
"flat_type": "PG",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": [
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "true", //these only
"_id": "55eac6065e1ddb87104a7866",
"rent": []
},
{
"tenant_id": null,
"agreement_start_date": null,
"agreement_end_date": null,
"rent_amt": 10000,
"rent_cycle": 7,
"advance_proof": null,
"id_proof": null,
"other_terms": null,
"is_active": "true", // theseonly
"_id": "55eb434f1d844381555c41c0",
"rent": []
}
]
},
{
"_id": "55ead22e232fe9585a86bb7e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eaf552b60c9f170fbe956e",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
},
{
"_id": "55eaf5b57eda5bcc155ee42c",
"building_id": "55eab32b358c513439c3ce5c",
"current_owner": "support@google.org",
"flat_name": "300",
"flat_floor": "Second Floor",
"flat_type": "2BHK",
"__v": 0,
"flat_tenant_old": [],
"flat_tenant": []
}
Could someone help me to solve this issue?