繁体   English   中英

MongoDB查询条件无法正常工作流星/ JavaScript

[英]MongoDB query criteria not working correctly Meteor / JavaScript

我有一个Products集合,其属性名为“ productCode”。 我正在尝试编写服务器端查询以基于productCode属性返回产品,但是我不断收到“无法读取未定义的'propertyCode'属性'”错误。

这是我的方法调用:

Meteor.call('findProduct', searchVal, function(error, a) {
        if(error) {
            alert(error.reason)
        } else {
            console.log('search success!');
        }
    });

这是我的methods.js代码,给我该错误:

'findProduct': function(searchVal, a) {
    a = Products.findOne({productCode: searchVal});
    return a; //return the product of interest
}

错误:传递调用“ findProduct”的结果时出现异常:TypeError:无法读取未定义的属性“ productCode”

但是,如果我在产品代码中进行硬编码,则可以使用:

'findProduct': function(searchVal, a) {
    a = Products.findOne({productCode: 9021073});
    return a; //this will return the product
}

在我的终端控制台中,它也可以正常工作:

db.products.findOne({productCode: 291105300});

有什么想法我可能做错了吗?

嗯-原因最初是字符串。 我使用parseInt将其转换为Integer并成功了!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM