как отобразить поля которых нету в схеме mongoose?

user.schema.ts

import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import * as mongoose from "mongoose";
import { Role } from "./role.schema";
// import { Role } from "./user.schema";

export type UserDocument = User & Document;

@Schema()
export class User {

    @Prop({ required: true, unique: true })
    name: string;


    @Prop({ required: true })
    password: string


    @Prop({ required: true, default: 'default.png' })
    avatar: string


    @Prop({ required: true, default: Date.now() })
    createdDate: Date


    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: "User" })
    teamLeader: User


    @Prop({ type: mongoose.Schema.Types.ObjectId, ref: "Role" })
    role: Role
}

export const UserSchema = SchemaFactory.createForClass(User)

user.service.ts

async getAll(): Promise<any> {
    const users = await this.userModel.find()
        .populate({ path: 'teamLeader', select: ['name', 'avatar'] })
        .populate({ path: 'role', select: ['name'] })
        .select('-password')
        .select('-__v')
        .exec();

    // const team = await this.userModel.find({ teamLeader: _id })

    return users
}

нужно вывести у всех юзеров поле team которое будет массивом с юзерами которых поле teamLeader равно _id данного юзера


Ответы (0 шт):