{"id":"6829b7a905105905","repo":"typeorm/typeorm","slug":"property-propertypath-was-not-found-in-met","errorCode":null,"errorMessage":"Property \"${propertyPath}\" was not found in \"${metadata.targetName}\". Make sure your query is correct.","messagePattern":"Property \"(.+?)\" was not found in \"(.+?)\"\\. Make sure your query is correct\\.","errorType":"exception","errorClass":"EntityPropertyNotFoundError","httpStatus":null,"severity":"error","filePath":"src/entity-manager/MongoEntityManager.ts","lineNumber":1238,"sourceCode":"                }\n\n                const embed =\n                    metadata.findEmbeddedWithPropertyPath(propertyPath)\n                if (embed) {\n                    if (value === true) {\n                        for (const subColumn of embed.columnsFromTree) {\n                            projection[subColumn.propertyPath] = 1\n                        }\n                    } else if (typeof value === \"object\") {\n                        build(value as ObjectLiteral, propertyPath)\n                    }\n                    continue\n                }\n\n                if (metadata.findRelationWithPropertyPath(propertyPath))\n                    continue\n\n                throw new EntityPropertyNotFoundError(propertyPath, metadata)\n            }\n        }\n        build(selects as ObjectLiteral, \"\")\n\n        // Translate ObjectIdColumn property name (e.g. \"id\") to \"_id\" for MongoDB\n        if (metadata.objectIdColumn) {\n            const propertyName = metadata.objectIdColumn.propertyName\n            if (\n                propertyName !== \"_id\" &&\n                projection[propertyName] !== undefined\n            ) {\n                projection[\"_id\"] = projection[propertyName]\n                delete projection[propertyName]\n            }\n        }\n\n        return projection\n    }","sourceCodeStart":1220,"sourceCodeEnd":1256,"githubUrl":"https://github.com/typeorm/typeorm/blob/04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96/src/entity-manager/MongoEntityManager.ts#L1220-L1256","documentation":"`MongoEntityManager` builds a Mongo field projection from the object-form `select`. For each key it checks for a column, an embedded, or a relation; if none match it throws `EntityPropertyNotFoundError`. This prevents projecting a field MongoDB cannot map back to an entity property.","triggerScenarios":"`mongoRepo.find({ select: { typoField: true } })`, selecting a relation that was renamed, or selecting a virtual property that is not persisted in Mongo.","commonSituations":"Renaming entity properties without updating select options; reusing relational `select` options after switching to Mongo.","solutions":["Make sure every key in `select` is a real column, embedded, or relation on the entity","Remove or fix typos in the select keys","Drop virtual/getter properties from the select object"],"exampleFix":"// before\nmongoRepo.find({ select: { usrname: true } })\n// after\nmongoRepo.find({ select: { username: true } })","handlingStrategy":"validation","validationCode":"function validateMongoSelect(metadata: EntityMetadata, select: Record<string, unknown>) {\n  for (const key of Object.keys(select)) {\n    const ok = metadata.findColumnWithPropertyPath(key) || metadata.findEmbeddedWithPropertyPath(key) || metadata.findRelationWithPropertyPath(key)\n    if (!ok) throw new Error(`select key ${key} is not a column/embedded/relation`)\n  }\n}","typeGuard":"function isValidMongoSelectKey(metadata: EntityMetadata, key: string): boolean {\n  return !!(metadata.findColumnWithPropertyPath(key) || metadata.findEmbeddedWithPropertyPath(key) || metadata.findRelationWithPropertyPath(key))\n}","tryCatchPattern":null,"preventionTips":["Derive select keys from the entity property list rather than hardcoding strings","Add a unit test asserting select keys exist on entity metadata"],"tags":["mongodb","select","projection","validation"],"analyzedSha":"04ff4daedcf60fa4ffd0d5d33bbafaac1a9bbc96","analyzedAt":"2026-08-03T18:27:32.281Z","schemaVersion":2}