loopback-connector-mongodb icon indicating copy to clipboard operation
loopback-connector-mongodb copied to clipboard

v.match is not a function

Open MrShadow50 opened this issue 1 year ago • 1 comments

The function below is fixed and merged in the v5.x branch but wasn't released for loopback3. Is there a specific version which support loopback3 and have this fix.

function isObjectIDProperty(modelCtor, propDef, value, options) {
  if (!propDef) return false;

  if ((typeof value === 'string' && value.match(ObjectIdValueRegex)) ||
    (Array.isArray(value) && value.every((v) => v.match(ObjectIdValueRegex)))) {
    if (isStoredAsObjectID(propDef)) return true;
    else return !isStrictObjectIDCoercionEnabled(modelCtor, options);
  } else if (value instanceof mongodb.ObjectID) {
    return true;
  } else {
    return false;
  }
}

MrShadow50 avatar Aug 09 '24 06:08 MrShadow50

It is never too late :) I also still have an old api under LB3 with a lot of patches :(

 function isObjectIDProperty(modelCtor, propDef, value, options) {
   if (!propDef) return false;

   if ((typeof value === 'string' && value.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) {
     return true;
   } else {
     return false;
   }
 }

brieucdlf avatar Oct 30 '25 10:10 brieucdlf