Express JS:奇怪的字符串比较

时间:2015-03-26 09:57:13

标签: javascript string node.js express mongoose

我这样做:

res.jsonp({
     userId:  user._id,
     spotUserId:  spot.user._id, 
     condition:  (user._id === spot.user._id)
});

结果如下:

{
    "userId": "551192836bff030fb657777c",
    "spotUserId": "551192836bff030fb657777c",
    "condition": false
}

我不明白为什么病情是假的......救命我!

1 个答案:

答案 0 :(得分:0)

哦,我解决了这个问题。

在ExpressJS中用于比较Mongoose ObjectsID, .id 不是 _id

示例:

res.jsonp({
    userId:  user._id,
    spotUserId:  spot.user._id, 
    condition:  (user.id === spot.user.id)
});

结果:

{
    "userId": "551192836bff030fb657777c",
    "spotUserId": "551192836bff030fb657777c",
    "condition": true
}