MongoDB查询条件无法正常工作Meteor/JavaScript
我有一个名为productCode的属性的产品集合。我正试图编写一个服务器端查询,以返回基于productCode属性的产品,但我一直得到一个无法读取的属性'propertyCode',该属性有未定义的错误 下面是我的方法调用:MongoDB查询条件无法正常工作Meteor/JavaScript,javascript,mongodb,meteor,Javascript,Mongodb,Meteor,我有一个名为productCode的属性的产品集合。我正试图编写一个服务器端查询,以返回基于productCode属性的产品,但我一直得到一个无法读取的属性'propertyCode',该属性有未定义的错误 下面是我的方法调用: Meteor.call('findProduct', searchVal, function(error, a) { if(error) { alert(error.reason) } else {
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把它转换成一个整数,它成功了 您的意思是无法读取未定义的属性“productCode”,还是在您得到的错误中它真的是“propertyCode”?如何调用该方法?如果没有使用第二个参数,为什么要传入它?您在哪个控制台中看到错误浏览器或终端?@boombox我用从浏览器粘贴的准确错误副本更新了我的问题console@DavidWeldon我用方法调用更新了我的问题。我在浏览器控制台中看到错误。我的终端控制台显示“undefined”(未定义),如果在执行Meteor.call时输入了正确的值,请检查searchVal。