0
以下代碼在集合中填充某個信息時觸發客戶端。有時它不適用於智能手機,但在桌面版Chrome上運行良好。
在集合上調用find
和findOne
是否正確?不是過度殺人? THX流星雨收集觀測變化
'myMethod': function (age, health) {
Meteor.call('doStuff-that-will-change-the-document');
myCollection.find().observeChanges({ // <===== find
changed: function (id, fields) {
let newDoc = myCollection.findOne({age: age}); // <==== another findOne
Meteor.users.update({_id: Meteor.user()._id}, {$unset: {'profile.taskInProgress': ''}});
if (newDoc) {
if (fields.filed1) {
lib.dothis1(newDoc, health);
} else if (fields.field2) {
lib.dothat(newDoc, health);
}
}
}
});
},
編輯
我需要的客戶端代碼火lib.dothis1
或lib.dothat
當field1
和field2
分別得到更新。
我再次探討了這個問題,目前還不清楚'年齡'如何通知一個新的文檔,所以也許我誤解了這個問題 - 如果讓我知道,並澄清你希望用'findOne'達到什麼目的。 – kabanus