我对猫鼬该员工架构:添加一个字段,猫鼬发现查询结果
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,
});
我有我的功能查找员工:
module.exports.getEmployeeById = function(id, callback){
Employee.find({ {id: id} }, callback);
}
但我想在我的Schema的所有字段旁边有一个结果字段,这是一个数组,用于拥有managerId:id(该员工以下的员工)的员工。
感谢
我不觉得这提供了足够的细节值得一个完整的答案,但你正在寻找什么被称为填充(像SQL连接):http://mongoosejs.com/docs/populate.html – supersam654
我不知道不想填充我的模型或数据库我想在查询json r中添加一个字段esponse –
@YassineBHS假设你不想像前面提到的那样使用'populate',那么简单的循环有什么问题? – georoot