here is my schema:
var UserSchema = new Schema({
email: String,
name: String,
city: String,
username: String,
profilePic: String,
phoneNo
Use select property in populate as:
User.populate(user, { path: 'shortList.flat.project', model: 'Project', select: 'name' })
This will give you name of project only.
To give specify fields which you don't want you can zero as:
User.populate(user, { path: 'shortList.flat.project', model: 'Project', select: { 'name': 0, 'Floor': 0, 'flats': 0, 'towers': 0,} }
This works for me.
and if you are doing two level populations:
we can simply do it as:
populate('project.tower', 'name project flats');
for a simple populate to get specific feilds:
populate('project', 'name')
try to do this:
applicantListToExport: function (query, callback) {
this
.find(query).select({'advtId': 0})
.populate({
path: 'influId',
model: 'influencer',
select: { '_id': 1,'user':1},
populate: {
path: 'userid',
model: 'User'
}
})
.populate('campaignId',{'campaignTitle':1})
.exec(callback);
}