I am populating a user collection in mongoose and want to set a flag if the user is signed up using social accounts. So I am selecting that fields in populate. But due to security concerns I don't want to pass it in response. So I converted it into plain object using lean()
and set the values as null
. But once a values are set null
for a particular user then it set that values null for that user_id
. How set them null
or how to hide them from response.
Pins.find(condition)
.limit(limit)
.sort({time: -1})
.populate({
path: 'user_id',
select: '_id name pic twitter_id fb_id',
options: { lean: true}
})
.lean()
.exec(function(err, data) {
if(data){
var flag = 0
async.eachSeries(data, function(v, callback1) {
if(v.user_id.twitter_id || v.user_id.fb_id ){
v.socialaccount=1
v.user_id.fb_id =''
v.user_id.twitter_id =''
}else{
v.socialaccount=0
v.user_id.fb_id =''
v.user_id.twitter_id =''
}
callback1()
},function(){
console.log(data)
callback(data)
})
} else {
callback(data)
}
})
Thanks in advance