How one entity name maps onto a physical Mongo collection.
collection: string
The collection name. Defaults to the entity name itself, so
getRepository('users') needs no mapping at all.
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).
idType: "objectId" | "raw" | "compound"
How the collection stores its _id values.
'objectId'forces the id to a driverObjectIdon read and write.'raw'forbids conversion, so astringid 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 thatObjectId.isValidaccepts — a 24-hex string. A non-string id (anumberkey) is passed through verbatim, because the driver'sisValidanswerstruefor 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.