loopbackio / loopbackio/loopback-connector-mongodb
ObjectID matching on array broken in 5.x line, fixed in 6.x line
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 186
- Forks
- 238
- Avg merge
- 2h 49m
- Merged PRs (30d)
- 1
Description
## Steps to reproduce
Install 5.6.0, pass an array of ObjectId's in a query such as:
app.models.catalog.find({}, function(err,catalogs) {
let catalogIds=[];
for(let i=catalogs.length; i>0; i--) catalogIds.push(catalogs[i-1].id);
app.models.registry.find({where:{ catalogId: { in: catalogIds}}}, function()...
## Current Behavior
**typeError: v.match does not exist**
## Expected Behavior
successful query lookup
## Link to reproduction sandbox
## Additional information
@@ -2167,7 +2169,7 @@
if (!propDef) return false;
if ((typeof value === 'string' && value.match(ObjectIdValueRegex)) ||
- (Array.isArray(value) && value.every((v) => v.match(ObjectIdValueRegex)))) {
+ (Array.isArray(value) && value.every((v) => typeof v === 'string' && v.match(ObjectIdValueRegex)))) {
if (isStoredAsObjectID(propDef)) return true;
else return !isStrictObjectIDCoercionEnabled(modelCtor, options);
} else if (value instanceof mongodb.ObjectID) {
## Related Issues
_See [Reporting Issues](http://loopback.io/doc/en/contrib/Reporting-issues.html) for more tips on writing good issues_
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the ObjectID validation logic involved in the 5.6.0 query path and reproduce the reported lookup with an array of ObjectIds. The issue is done when the array query succeeds without the “v.match does not exist” TypeError, while preserving the existing behavior for string ObjectIds.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, mongodb
- Domain
- database
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100