Change local collection without affecting the server collection

how can I change some fields in a collection that is also in the server but only locally.
for example, I want to change my user name but only locally (in Meteor.users), suppose is to give a preview functionality

I do not want to have to use a null collection because that would add more complexity to my application

When executed the following method I can see for a moment the changes, I want to achieve some way to keep it

Meteor.methods({
  changeName: function (name) {
   Meteor.users.update(this.userId, {$set: 'profile.name': name});
  }
});

Sadly, there is no reliable way to do that. You can try to toy with Meteor.users._collection, which represents the local cache, but you will soon realize it is modified by Meteor in unpredictable ways. Use a null collection with an observer: it doesn’t add so much complexity and is surprisingly fast.

1 Like

Use a null collection with an observer: it doesn’t add so much complexity and is surprisingly fast.

Elementary, my dear Watson, Now I have everything ready to make a great package!

Wouldn’t it lose it’s reactivity, and is there a package?

Local Collections have reactivity.

Depends on what you want, but one thing you could do is

return _.get(TemporaryUsers.findOne(userId), 'field') || _.get(Meteor.users.findOne(userId),'field')

(requires lodash, or mixin for underscore)
This way, the temporary user takes precedence if has the field, otherwise show the regular field.

Looks good. Supposedly if I were to run this Meteor.users.findOne and move it into explicitly local collection within tracker it would keep local collection updated.