Monday, 24 April 2017

Adding a field to mongoose find query result

I have this employee schema in mongoose :

employeesSchema = mongoose.Schema({
    id: {
        type: Number,
        required: true
    },
    firstName: String,
    lastName: String,
    title: String,
    managerId: {
        type:Number,
        required: false
    },
    managerName: {
        type: String,
        required: false
    },
    phone: String,
    mobilePhone: String,
    email: String,
    picture: String,
});

And I have my function to find employee :

module.exports.getEmployeeById = function(id, callback){

Employee.find({ {id: id} }, callback);

}

but I want to have a one more field in result beside all the fields of my Schema, a field that is an array for the employees who has managerId:id ( the employees below this employee).

Thanks



via Yassine BHS

No comments:

Post a Comment