#Best Practice for Handling _id in a TypeScript Node.js App with MongoDB?
3 messages · Page 1 of 1 (latest)
In my app I do this when sending away data
export function transformEntity<T>(entity: T): TransformedEntity<T> {
const { _id, __v, ...restOfTheProperties } = entity as T & { _id: string; __v: number }
return {
id: _id,
...restOfTheProperties,
}
}
@Schema({
toJSON: {
transform: (_doc, ret: Entity) => transformEntity<Entity>(ret),
},
})