Meteor-Community-Packages / meteor-partitioner

Transparently divide a single meteor app into several different instances shared between different groups of users.
152 stars 18 forks source link

Replace upsert with update to prevent adding empty records. #14

Closed kristijanhusak closed 8 years ago

kristijanhusak commented 9 years ago

This fixes the issue with inserting empty data into the collections.

I have situation where i need to delete a user. This is the code i'm running on server to achieve that:

    Partitioner.clearUserGroup(userId);
    Users.remove({_id: userId});

Partitioner properly removes entry from ts.grouping collection, but removed "hook" is triggered afterwards, probably several times, and inserts the user back to the table with the _id field only. I also tried doing something like this, but it didn't help:

Grouping.remove(userId, function() {
  Users.remove({_id: userId });
});

// With collection hooks package
Grouping.after.remove(userId, function(userId, doc) {
  Users.remove({_id: doc._id });
});

This should fix the problem because update will only work if entry exists in the collection.

mizzao commented 9 years ago

That looks fine to me.

More generally though, do you think that getUserGroup, setUserGroup and clearUserGroup should throw an error if the user doesn't exist?

kristijanhusak commented 9 years ago

I think only writable methods should throw error, so setUserGroup and clearUserGroup. getUserGroup is just a getter.

mizzao commented 9 years ago

Oh right, of course. Sounds good and I will update this accordingly.

djenniex commented 8 years ago

Any idea when this fix will make it into a release? I'm having issues with blank users being created also.

mizzao commented 8 years ago

Yes, thanks for the ping! Just released 0.5.9 with this merged.

mizzao commented 7 years ago

Btw @kristijanhusak, would you mind if I added you as a collaborator on this repo (and publish access for Meteor) so you can merge in your nice features on your branch?