【发布时间】:2017-11-05 04:41:45
【问题描述】:
以下代码在集合中填充特定信息时触发客户端。有时它不能在智能手机上运行,但在桌面 Chrome 上运行良好。
在集合上调用find 和findOne 是否正确?不是过度杀戮?谢谢
'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);
}
}
}
});
},
编辑
当field1 和field2 分别更新时,我需要客户端代码触发lib.dothis1 或lib.dothat。
【问题讨论】:
标签: meteor