Ok, I’ve spent a lot of time making this work with observechanges() but no success.
I have the following query:
`Meteor.publish(‘empresas_invalidas_inspetor’, function() {
if (Roles.userIsInRole(this.userId, ZW.Roles.Inspetor))
{
var inspetor = Inspetor.findOne({id_user: this.userId});
var ids = Meteor.users.find({ roles: {$eq: “empresa”, $ne: “validado”}}, {fields: {_id: 1}}).map(function(item){ return item._id; });
What I want is when and the user roles changes, it reruns the “user find map” statment and then the “empresa find” statement.
Any ideias on how can simply achieve this, and please if you can explain how it works, because even reading the observechanges docs I can’t understand exactly whats happening there.
Publications are not inherently reactive. So, changing a user’s roles will not necessarily re-run the publication with new data. There are a couple of ways you can address this:
Use the client to pass a “roles have changed” parameter to the publication to force a re-publish.
Thank you for your time, but just adding the ready() method didn’t make the subscription reactive.
And I used the new query you gave me, but that doesn’t seem to have anything in special besides the _pluck method, that I believe to be a helper function of loadsh?.