mongo文件的_id在玉石上减去一个

时间:2014-11-09 03:14:08

标签: node.js mongodb express mongoose pug

我发现节点控制器,数据库(mongodb)和引擎模板jade之间存在罕见的问题。我会在解释你之后展示这段代码。

代码

控制器:

router.get('/get_my_buildings', function(req, res)
{
    if(req.session && req.session.user && (req.session.user.rol=="Admin" ||    req.session.user.rol=="superAdmin"))
        buildingDB.getBuilding({admin_id:req.session.user._id}, function(results)
        {
            if(results.error==1 || results.result.length==0) res.render('resource_not_found');
            else res.render('buildings/admin_buildings', {title:"WELLCOME", user:req.session.user, buildings: results.result});
        });
    else    res.render('users/loggin', {title:"LOGGING"});
});

玉:

div(style="display: table;")
    for building in buildings
        div(style="display: table-row;" class="search_hit")
            div(style="display: table-cell;" class="not_search")
                span.glyphicon.glyphicon-map-marker
            div(style="display: table-cell;" class="inline") #{building.address[0].address}
            div(style="display: table-cell;" class="inline") #{building.address[0].city}
            div(style="display: table-cell;" class="inline") #{building.address[0].province}
            div(style="display: table-cell;" class="inline not_search input-group input-group-sm")
                a(type="button" href="/setup_building/#{building.address[0]._id}" class="btn btn-info inline")
                    span.glyphicon.glyphicon-tags.right-margin
                    |Setup
    else
        li I´m sorry, there is no building to show.

我发现的问题是: href =“/ setup_building /#{building.address [0] ._ id}”总是在id处减去一个比它应该写的一个。 例如,应该写的id是:545d384b9c33e76c07ba510d,但它写道:545d384b9c33e76c07ba510e。
所有其他日期都是正确的。我究竟做错了什么??

非常感谢。
PS:我正在使用快递

1 个答案:

答案 0 :(得分:0)

我现在知道这个问题。当我提出“所有建筑物”请求时,这就是结果:

{
    "_id": "545d384b9c33e76c07ba510d",
    ...
    "address": [{
        ...
        "_id": "545d384b9c33e76c07ba510e"
    }]
}, {
    "_id": "545d5afc8e0295001bdf44e0",
    ...
    "address": [{
        ...
        "_id": "545d5afc8e0295001bdf44e1"
    }]
}

_id上有两个非常相似的buildingid的{​​{1}}个building以及_id对象的address非常相似:

building: 545d384b9c33e76c07ba510d  
address:  545d384b9c33e76c07ba510e