Created
June 3, 2020 13:57
-
-
Save jampajeen/279d51d9e3beba55d546c1c2d911d85b to your computer and use it in GitHub Desktop.
Nestjs mongoose use UUID as an id
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; | |
import { Document } from 'mongoose'; | |
import { v4 as uuidv4 } from 'uuid'; | |
@Schema() | |
export class Course extends Document { | |
@Prop({ type: String, default: function genUUID() { | |
return uuidv4() | |
}}) | |
_id: string | |
} | |
export const CourseSchema = SchemaFactory.createForClass(Course); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.