Hi,
Typical use case in a denormalized scheme: Bob changes his username, so all documents that have his username must be manually updated.
Solution 1: Observe the entire user’s collection by query == {}. IIUC, this observer will run N times if there are N people connected. That sounds like awful redundancy.
//in app's server side code
Meteor.users.find({},{fields:{username:1}}).observeChanges({
changed: function(id,fields){
//update all docs to reflect changes;
}
});
Solution 2: Kill the redundancy by observing a much smaller collection set per connection, namely, the current user’s object ONLY.
//in app's server side code
var currentUserId = Meteor.userId();
Meteor.users.find(currentUserId,{fields:{username:1}}).observeChanges({
changed: function(id,fields){
//update all docs to reflect changes;
}
});
Solution 3: Forget an in-app solution, and run a secondary meteor process whose sole purpose is to observe the database for these operations.
//in a completley different meteor app, server side code.
Meteor.users.find({},{fields:{username:1}}).observeChanges({
changed: function(id,fields){
//update all docs to reflect changes.
}
});
Solution 1: Runs N observers which all observe all documents in the Meteor.users collection.
Solution 2: Runs N observers which only observe the user from which the observer was instantiated.
Solution 3: Runs a single observer, which observes all documents in the Meteor.users collection.
Is my reasoning correct that Solution 1 is unecessesary and redundant because solution 2 achieves the exact same thing? What are your thoughts on solution 3?