I am encountering an issue with a Products collection that has an attribute called "productCode". My goal is to create a server-side query to fetch a product based on the productCode attribute. Unfortunately, I keep running into a "cannot read property 'propertyCode' of undefined" error.
Below is the snippet of my method call:
Meteor.call('findProduct', searchVal, function(error, result) {
if(error) {
alert(error.reason)
} else {
console.log('Search successful!');
}
});
Furthermore, here is the snippet from my methods.js file that is triggering the aforementioned error:
'findProduct': function(searchVal, result) {
result = Products.findOne({productCode: searchVal});
return result; //return the desired product
}
Error: Exception in delivering result of invoking 'findProduct': TypeError: Cannot read property 'productCode' of undefined
Interestingly, when I manually input the product code, it functions properly as shown below:
'findProduct': function(searchVal, result) {
result = Products.findOne({productCode: 9021073});
return result; //this will retrieve the specific product
}
In addition, executing this query directly in my terminal console yields the expected result:
db.products.findOne({productCode: 291105300});
Could you provide any insights into what might be causing this unexpected behavior?