I am using Offline Persistence Toolkit in a Oracle JET application, and I am getting an error when trying to find a document inside my local store.
The issue happens when I need to query a document using the helper function store.find() using $regex in the expression I want to evaluate against (I want to match anything that has 'last' in the property lastName). For example, I am doing the following:
However, some of my objects in the store don't have the lastName property, so when the plugin is analyzing those objects that don't have that property, it breaks and doesn't return me anything.
Checking the plugin source code, I realized that the function _evaluateExpressionTree inside storageUtils is using the method .match() on every object inside my store:
else if (operator === '$regex') {
var matchResult = itemValue.match(value);
return matchResult !== null;
}
Whenever an object that doesn't have the property is being evaluated, I get the following error:
error retrieving all documents from pouch db, returns empty list as find operation. TypeError: Cannot read property 'match' of undefined.
So, my work around to get it working was to add a check if itemValue is not undefined before matching the value.
I am using Offline Persistence Toolkit in a Oracle JET application, and I am getting an error when trying to find a document inside my local store.
The issue happens when I need to query a document using the helper function store.find() using $regex in the expression I want to evaluate against (I want to match anything that has 'last' in the property lastName). For example, I am doing the following:
persistenceStoreManager.openStore('contacts').then((store) => { store.find({ selector: { 'value.lastName': { $regex: 'last' } } }) .then(users => { self.allUsers(users); }); });
However, some of my objects in the store don't have the lastName property, so when the plugin is analyzing those objects that don't have that property, it breaks and doesn't return me anything.
Checking the plugin source code, I realized that the function _evaluateExpressionTree inside storageUtils is using the method .match() on every object inside my store:
else if (operator === '$regex') { var matchResult = itemValue.match(value); return matchResult !== null; }
Whenever an object that doesn't have the property is being evaluated, I get the following error:
error retrieving all documents from pouch db, returns empty list as find operation. TypeError: Cannot read property 'match' of undefined.
So, my work around to get it working was to add a check if itemValue is not undefined before matching the value.