0
我有一個產品集合,其中包含一個名爲「productCode」的屬性。我正在嘗試編寫一個服務器端查詢來返回基於productCode屬性的產品,但我一直收到「無法讀取屬性'propertyCode'的未定義」錯誤。MongoDB查詢條件無法正常工作流星/ JavaScript
這裏是我的方法調用:
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
}
錯誤:異常在提供援引「查找產品信息」的結果: TypeError:無法讀取屬性'productCode'的undefined
但是,如果我在產品代碼中硬編碼,它的工作原理如下:
'findProduct': function(searchVal, a) {
a = Products.findOne({productCode: 9021073});
return a; //this will return the product
}
在我的終端控制檯,這個作品,以及:
db.products.findOne({productCode: 291105300});
任何想法我可能是做錯了?
你的意思是「不能讀取屬性''productCode'' of undefined」或者它真的是'propertyCode'中的錯誤嗎? – boombox
如何調用該方法?爲什麼傳入第二個參數,如果它沒有被使用?你在哪個控制檯看到錯誤(瀏覽器或終端)? –
@boombox我更新了我的問題,確切的錯誤(從瀏覽器控制檯複製並粘貼) –