Hello,
I have the following schema
User {
_id
name
screencolor
username
}
Post {
_id
comment
author
replyTo
nextSibling
previousSibling
topReplies
}
Since Im saving an entire conversation, if a post has a replyTo (parent) attribute set, it will probably have either previous Sibling or next Sibling, and it might have top replies, but if it has no parent it will have no siblings.
Im doing the following query:
Post.find( { draft: false } ).sort({createdAt: -1})
.populate({path: 'previousSibling nextSibling topReplies replyTo', select: '_id author'})
.populate({path: 'author', select: 'username screencolor'})
.exec(function(err, posts) {
if(err){
return next(new restify.ConflictError(err));
}
if (posts.length === 0) {
return next(new restify.NotFoundError("No Posts Found"));
} else {
User.populate(posts, {path: 'previousSibling.author nextSibling.author topReplies.author replyTo.author', select: 'username name screencolor'}, function(err, docs) {
res.json(200, docs);
return next();
});
}
});
};
Now its understandable from this post that the intended way that mongoose works is that populates returns null if the field requested does not return anything, but is there a way to not return null fields at all, or return something else?
Thank you!