typeorm/typeorm · error · EntityPropertyNotFoundError

Property "${propertyPath}" was not found in "${metadata.targ

Error message

Property "${propertyPath}" was not found in "${metadata.targetName}". Make sure your query is correct.

What it means

`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.

Source

Thrown at src/entity-manager/MongoEntityManager.ts:1238

                }

                const embed =
                    metadata.findEmbeddedWithPropertyPath(propertyPath)
                if (embed) {
                    if (value === true) {
                        for (const subColumn of embed.columnsFromTree) {
                            projection[subColumn.propertyPath] = 1
                        }
                    } else if (typeof value === "object") {
                        build(value as ObjectLiteral, propertyPath)
                    }
                    continue
                }

                if (metadata.findRelationWithPropertyPath(propertyPath))
                    continue

                throw new EntityPropertyNotFoundError(propertyPath, metadata)
            }
        }
        build(selects as ObjectLiteral, "")

        // Translate ObjectIdColumn property name (e.g. "id") to "_id" for MongoDB
        if (metadata.objectIdColumn) {
            const propertyName = metadata.objectIdColumn.propertyName
            if (
                propertyName !== "_id" &&
                projection[propertyName] !== undefined
            ) {
                projection["_id"] = projection[propertyName]
                delete projection[propertyName]
            }
        }

        return projection
    }

View on GitHub (pinned to 04ff4daedc)

Solutions

  1. Make sure every key in `select` is a real column, embedded, or relation on the entity
  2. Remove or fix typos in the select keys
  3. Drop virtual/getter properties from the select object

Example fix

// before
mongoRepo.find({ select: { usrname: true } })
// after
mongoRepo.find({ select: { username: true } })
Defensive patterns

Strategy: validation

Validate before calling

function validateMongoSelect(metadata: EntityMetadata, select: Record<string, unknown>) {
  for (const key of Object.keys(select)) {
    const ok = metadata.findColumnWithPropertyPath(key) || metadata.findEmbeddedWithPropertyPath(key) || metadata.findRelationWithPropertyPath(key)
    if (!ok) throw new Error(`select key ${key} is not a column/embedded/relation`)
  }
}

Type guard

function isValidMongoSelectKey(metadata: EntityMetadata, key: string): boolean {
  return !!(metadata.findColumnWithPropertyPath(key) || metadata.findEmbeddedWithPropertyPath(key) || metadata.findRelationWithPropertyPath(key))
}

Prevention

When it happens

Trigger: `mongoRepo.find({ select: { typoField: true } })`, selecting a relation that was renamed, or selecting a virtual property that is not persisted in Mongo.

Common situations: Renaming entity properties without updating select options; reusing relational `select` options after switching to Mongo.

Related errors


AI-assisted analysis of typeorm/typeorm@04ff4daedc (2026-08-03). Data as JSON: /data/errors/6829b7a905105905.json. Report an issue: GitHub.