Node.js mongoose findById在使用字符串文字时有效,但在引用对象的属性时无效
我在猫鼬身上遇到了一个非常奇怪的问题 此行正确地找到了Node.js mongoose findById在使用字符串文字时有效,但在引用对象的属性时无效,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,我在猫鼬身上遇到了一个非常奇怪的问题 此行正确地找到了轮: models.Round.findById("555ec731385b4d604356d8e5", function(err, roundref){ console.log(roundref); .... 这条线不行 models.Round.findById(result.round, function(err, roundref){ console.log(r
轮
:
models.Round.findById("555ec731385b4d604356d8e5", function(err, roundref){
console.log(roundref);
....
这条线不行
models.Round.findById(result.round, function(err, roundref){
console.log(roundref);
我已经记录了result
,它显然是一个包含属性round的对象:
{round: "555ec731385b4d604356d8e5", selection: 1, time: 20}
如果
result
是一个JSON字符串,调用。round
将返回未定义的
首先尝试将JSON转换为javascript对象:
result = JSON.parse(result);
models.Round.findById(result.round, function(err, roundref){
console.log(roundref);
如果result
是一个JSON字符串,调用.round
将返回未定义的
首先尝试将JSON转换为javascript对象:
result = JSON.parse(result);
models.Round.findById(result.round, function(err, roundref){
console.log(roundref);
你确定result
是一个javascript对象而不是JSON字符串吗?@victorkohl你是对的!那是一根绳子!!请回答,我会接受你确定result
是一个javascript对象而不是JSON字符串吗?@victorkohl你是对的!那是一根绳子!!请回答,我会接受你确定result
是一个javascript对象而不是JSON字符串吗?@victorkohl你是对的!那是一根绳子!!请回答,我会接受的