mongoose findById当我使用一个string文字,但不是当我引用一个对象的属性时工作

我在Mongoose中遇到了一个非常奇怪的问题。

这条线正确地findRound

 models.Round.findById("555ec731385b4d604356d8e5", function(err, roundref){ console.log(roundref); .... 

这条线不是

 models.Round.findById(result.round, function(err, roundref){ console.log(roundref); 

我已经控制loginresult ,它显然是一个对象包含属性轮:

 {round: "555ec731385b4d604356d8e5", selection: 1, time: 20} 

为什么找不到findById工作?

如果result是JSONstring,则调用.round将返回undefined

尝试首先将JSON转换为JavaScript对象:

 result = JSON.parse(result); models.Round.findById(result.round, function(err, roundref){ console.log(roundref);