Setu-TS
    Preparing search index...

    Interface MongoEntityMapping

    How one entity name maps onto a physical Mongo collection.

    0.2.0

    interface MongoEntityMapping {
        collection?: string;
        idType?: "raw" | "objectId" | "compound";
        primaryKey?: string | readonly string[];
    }
    Index
    collection?: string

    The collection name. Defaults to the entity name itself, so getRepository('users') needs no mapping at all.

    idType?: "raw" | "objectId" | "compound"

    How the collection stores its _id values.

    • 'objectId' forces the id to a driver ObjectId on read and write.
    • 'raw' forbids conversion, so a string id is passed to the driver verbatim.
    • 'compound' stores a composite key as a subdocument _id, built in the mapping's declared column order (P5 — canonical order, not caller order). Absent converts a string id that ObjectId.isValid accepts — a 24-hex string. A non-string id (a number key) is passed through verbatim, because the driver's isValid answers true for any number while its constructor rejects one.

    The genuinely ambiguous collection — one whose _id values are 24-hex strings rather than ObjectIds — cannot be distinguished at runtime, so the override exists rather than being guessed.

    primaryKey?: string | readonly string[]

    The primary-key field name(s). Defaults to 'id'.

    A scalar names a single-column key (the driver's _id maps to that one field). An array names a composite key: each named column is a top-level field on the collection (idType absent) or, when idType: 'compound', the keys of the subdocument stored under the driver's _id in the mapping's declared order (P4/P5).