Skip to content

ObjectID matching on array broken in 5.x line, fixed in 6.x line #659

Open
@patrickdk77

Description

@patrickdk77

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 for more tips on writing good issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions