只获得特定的" is_active" =" true"数组只有Mongodb

时间:2015-09-06 09:51:27

标签: arrays node.js mongodb

我正在开发基于移动设备的API项目。现在我陷入了这个严肃而简单的问题。

如何才能获得仅显示(仅来自嵌入文档的真实数组)"flat_tenants.is_active" : "true"数组而不是"flat_tenants.is_active" : "false"数组

{
  "_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": []
}

我希望结果为

{
  "_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": []
}

有人可以帮我解决这个问题吗?

0 个答案:

没有答案