[solved] How to update ALL user profiles?


I have an app in wich users can…

  1. create new products
  2. mark products as “favorite”

So User A can “favorite” some products of User B and User C.
This adds the ids of those products to User A’s profile.favorites Array.

When a product is removed I’ll need to update the profile.favorites Array of every user.
I don’t know how to do this.

I’ve tried something like this:

    removeProduct: function(currentProduct){
        Meteor.users.update({}, {$pull: {'profile.favorites': currentProduct}});

This gives me the following error:
Error invoking Method 'removeProduct': Internal server error [500]

Any ideas, where I’m going wrong?

First of all, when you get an internal server error, you should look for the actual error message in your server logs. This will point you in the good direction.

Secondly, if you want to update multiple documents in your database you have to add a third, options parameter to your update call, like this: {multi: true}. Check out the docs for more information.

1 Like

Thanks, that did the trick :slight_smile: