我在mongo shell和从nodejs应用程序获取响应时获得了不同的输出结果。
请注意我是mongoose作为mongodb的nodejs驱动程序
下面给出的代码。
_id:ObjectId("55eab3cb358c513439c3ce5d")
building_id:"55eab32b358c513439c3ce5c";
flat_tenants:[{
"_id": {
"tenant_id": "",
"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": []
}
},
{
"_id": {
"tenant_id": "geo@g.org",
"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": []
}
},
{
"_id": {
"tenant_id": "geo2@g.org",
"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": []
}
},
{
"_id": {
"tenant_id": "geo3@g.org",
"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": []
}
}
]
}
mongo shell的输出:
"1" : {
"tenant_id" : "geo2@g.org",
"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" : ObjectId("55ead263232fe9585a86bb7f"),
"rent" : [ ]
}
通过nodejs app输出:
{
"_id": {
"tenant_id": "",
"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": []
}
},
{
"_id": {
"tenant_id": "geo@g.org",
"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": []
}
},
{
"_id": {
"tenant_id": "geo2@g.org",
"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": []
}
},
{
"_id": {
"tenant_id": "geo3@g.org",
"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": []
}
}
mongodb代码:
flats.aggregate({$match:{building_id: "55eab32b358c513439c3ce5c", _id:ObjectId("55eab3cb358c513439c3ce5d")}},
{$unwind:"$flat_tenant"},
{$match:{"flat_tenant._id": ObjectId("55eac5db5e1ddb87104a7865") }},
{ $project: { _id: 0, _id: "$flat_tenant" } } ).exec(function(err, tenantDetails1) {
有人可以帮我弄清楚为什么我会遇到这个问题。