I am building a quora of sorts.. and I am trying to clean up my website. Currently if a user deletes their profile, their question remains there and will display no user. I am trying to link it up users.
What I did was I added a field on the users db that changes from 'active to 'inactive'(there is no deletion).
So my question is how can I query mongo so I can only show questions by users that have the 'active' tag on the users db.
I have no idea how to do a cross database query. Is this the right way to do it and if so how is that possible?
Thanks!
- ANSWER -
- ANSWER -
You have a couple of options, but the easiest is just to mark the questions as inactive as soon as their author becomes inactive. Here's an example
deleteUser
method:Meteor.methods({
deleteUser: function() {
// mark the user as inactive
Meteor.users.update(this.userId, {$set: {isInactive: true}});
// mark the user's questions as inactive
Questions.update(
{author: this.userId},
{$set: {isInactive: true}},
{multi: true}
);
}
});
Because the data about inactive authors has already been propagated to the
Questions
collection, your publish function could look something like this:Meteor.publish('activeQuestions', function() {
// only return active posts
return Questions.find({isInactive: {$ne: true}});
});
0 comments:
Post a Comment