{"record":{"id":"79f1f37bb71c1f22","repo":"hcengineering/platform","slug":"unknown-predicate","errorCode":null,"errorMessage":"unknown predicate: ","messagePattern":"unknown predicate: ","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"foundations/core/packages/core/src/predicate.ts","lineNumber":156,"sourceCode":"        return false\n      })\n  }\n}\n\nexport function isPredicate (o: Record<string, any>): boolean {\n  if (o === null || typeof o !== 'object') {\n    return false\n  }\n  const keys = Object.keys(o)\n  return keys.length > 0 && keys.every((key) => key.startsWith('$'))\n}\n\nexport function createPredicates (o: Record<string, any>, propertyKey: string): Predicate[] {\n  const keys = Object.keys(o)\n  const result: Predicate[] = []\n  for (const key of keys) {\n    const factory = predicates[key]\n    if (factory === undefined) throw new Error('unknown predicate: ' + keys[0])\n    result.push(factory(o[key], propertyKey))\n  }\n  return result\n}\n","sourceCodeStart":138,"sourceCodeEnd":161,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/foundations/core/packages/core/src/predicate.ts#L138-L161","documentation":"createPredicates builds filter predicates from a $-keyed query object and looks each key up in the predicates table. If the key is not one of the supported predicates ($in, $all, $nin, $like, $regex, $gt, $gte, $lt, $lte, $exists, $ne, $size), it throws this error naming the first key of the object. It means the query used an unsupported or misspelled predicate.","triggerScenarios":"Queries like { name: { $contains: 'x' } } or { age: { $elemMatch: {...} } } (Mongo operators not implemented here), typos such as { $gte : ... } vs { $gtes: ... }, or nested objects mistakenly treated as predicates because all their keys start with '$'.","commonSituations":"Porting MongoDB queries assuming full operator coverage; typos; dynamic query builders emitting unsupported keys; passing user-supplied filter JSON directly into find().","solutions":["Use only the supported predicates listed in predicate.ts ($in, $all, $nin, $like, $regex, $gt, $gte, $lt, $lte, $exists, $ne, $size).","Fix the misspelled predicate name — note the message reports keys[0], so verify the first $-key of the object.","Emulate unsupported operators client-side: fetch with supported predicates then filter in code.","Validate user-supplied filters against an allow-list of predicate names before calling find()."],"exampleFix":"// before\nfind(docClass, { name: { $contains: 'foo' } })\n// after\nfind(docClass, { name: { $like: '%foo%' } })","handlingStrategy":"validation","validationCode":"const SUPPORTED_PREDICATES = ['$in', '$all', '$nin', '$like', '$regex', '$gt', '$gte', '$lt', '$lte', '$exists', '$ne', '$size']\nfunction validateFilter(filter: Record<string, Record<string, any>>): void {\n  for (const [field, preds] of Object.entries(filter)) {\n    for (const key of Object.keys(preds)) {\n      if (!SUPPORTED_PREDICATES.includes(key)) {\n        throw new Error(`unsupported predicate ${key} on field ${field}`)\n      }\n    }\n  }\n}","typeGuard":"function hasOnlyKnownPredicates(o: Record<string, any>, known: string[]): boolean {\n  return isPredicate(o) && Object.keys(o).every((k) => known.includes(k))\n}","tryCatchPattern":"try {\n  return await find(clazz, filter)\n} catch (e) {\n  if (e instanceof Error && e.message.startsWith('unknown predicate:')) {\n    const op = e.message.split('unknown predicate: ')[1]\n    console.error(`Filter uses unsupported predicate \"${op}\"; supported: $in $all $nin $like $regex $gt $gte $lt $lte $exists $ne $size`)\n  }\n  throw e\n}","preventionTips":["Type filters with a union of supported predicate keys so typos fail at compile time.","Sanitize user-supplied filter JSON against an allow-list before find().","When porting Mongo queries, replace $contains/$elemMatch/$type with supported alternatives or client-side filtering."],"tags":["query","predicate","validation"],"backgroundTag":"unknown-query-operator","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}