Horje
nestjs mongoose schema virtual Code Example
nestjs mongoose schema virtual
// user.schema.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type UserDocument = User & Document;

@Schema({
  toJSON: { // use toObject for objects
    virtuals: true,
  }
})
export class User {
  @Prop({ type: String })
  first_name: string;
  
  @Prop({ type: String })
  last_name: string;
  
  full_name: string;
}

const UserSchema = SchemaFactory.createForClass(User);
UserSchema.virtual('full_name').get(function (this: UserDocument) {
  return `${this.first_name} ${this.last_name}`;
});
export { UserSchema }
nestjs mongoose schema
// user.schema.ts
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document } from 'mongoose';

export type UserDocument = User & Document;

@Schema()
export class User {
  @Prop({ type: String, unique: true })
  username: string;
  
  @Prop({ type: String })
  password: string;
}

export const UserSchema = SchemaFactory.createForClass(User);




Typescript

Related
react-native gesturehandler modalize ios onpress Code Example react-native gesturehandler modalize ios onpress Code Example
roblox finding points around a circle using radius, center, and angle Code Example roblox finding points around a circle using radius, center, and angle Code Example
Error: Missing "key" prop for element in iterator Code Example Error: Missing "key" prop for element in iterator Code Example
how to get post of instragram using api Code Example how to get post of instragram using api Code Example
instragram basic api Display Code Example instragram basic api Display Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7