Suppose I have a user document which can change in 3 ways. Suppose observeChanges
is not an option.
Which option is more efficient? Three lean observers, or one bulky one?
Users.findOne() ...
... {
username: "Bob",
tags: ['batman','soccer','fish','electron'],
rating: 2.71828
}
Username can become a different string. Tags can becoming a larger or smaller array, or the values inside can change. Rating can become a new number.
//single bulky observer, will run and check if tags, rating changed even if only username changed.
Users.find().observe({
changed: function(newDoc, oldDoc){
//if username changed, do something
//if tags changed do something
//if rating changed, do something
}
})
//three observers, each very lean.
Users.find({},{fields:{tags:1}}).observe({
changed: (newDoc, oldDoc){
//we know what do to, no checking.
}
})
//and the other two, not gonna write them...