具有多选项的流星更新集合失败



为什么getcounter函数只被调用一次?

collect.update({sys_RowId: {$exists : false}},
  {$set: {sys_RowId: getcounter()}},{multi: true});     

是的,首先评估getcounter函数。传递给collect.update的JSON对象只包含其返回值。不可能将getcounter作为回调传递给更新方法。

您需要在forEach()循环中执行此操作:

collect.find(({sys_RowId: {$exists : false}}).forEach(function(doc){
  collect.update(doc._id, {$set: {sys_RowId: getcounter()}});  
});   

最新更新