Skip to content

Instantly share code, notes, and snippets.

@jampajeen
Created June 3, 2020 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jampajeen/279d51d9e3beba55d546c1c2d911d85b to your computer and use it in GitHub Desktop.
Save jampajeen/279d51d9e3beba55d546c1c2d911d85b to your computer and use it in GitHub Desktop.
Nestjs mongoose use UUID as an id
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);
@imerla1
Copy link

imerla1 commented Oct 24, 2022

Thanks.

@santiago-jv
Copy link

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment