I have a Community Schema:
var community = mongoose.Schema({
subject: String,
body: String,
members: [{
isModerator: { type: Boolean, default: false },
muted: { type: Boolean, default: false },
deactivated: { type: Boolean, default: false },
status: String, // waiting (only in default community), active, invited, blocked, muted
date: Date,
profile: { type: mongoose.Schema.Types.ObjectId, ref: 'profile' }
}]
});
I Want to get Only 1 member from the array of members in a community as i know profile id of that member in a community. But When I am trying to get it return whole Community details including all members. The way i tried is:
db.getCollection('communities').find({"_id":bjectId("593fe3cc32f9e76c7752fbbc"), "members.profile": {$eq: ObjectId("5949fa79948f3e18e0dea3bb")}}
)
Or by using Code:
var query={};
query.id = req.query.batchId;
query['members.profile'] = {
$eq: req.query.profileId
};
db.community.findOne(query)
.populate('members.profile')
.exec(function(err, member){
if(err){
return res.failure(err);
}
return res.success();
});
I understand as i am trying to get(find) community that is why it return whole community. But my Question is how can i get only 1 member from Array of Members in a community while getting community? Any Help would be appreciated.