Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js mongoose findById在使用字符串文字时有效,但在引用对象的属性时无效_Node.js_Mongodb_Mongoose - Fatal编程技术网

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你是对的!那是一根绳子!!请回答,我会接受的