代码之家  ›  专栏  ›  技术社区  ›  Phung D. An

在meteor mongdb中删除某个用户时更新所有联系人列表

  •  1
  • Phung D. An  · 技术社区  · 7 年前

    我们正在开发联系人列表的一个简单功能(这是朋友列表的一个简单版本)。

    here ,我将contact_id存储在每个用户的联系人中,以便userA可以:

    1. 通过将用户添加到其联系人

      流星用户。更新(Meteor.userId(),{$push:{contacts:newId});

    2. 去除

      流星用户。更新(Meteor.userId(),{$pull:{contacts:existingId});

    现在,如果userB决定删除他的帐户,该怎么办?循环访问近一百万个用户,从联系人中提取userB id

    1 回复  |  直到 7 年前
        1
  •  2
  •   Michel Floyd    7 年前

    您可以在一次mongo更新中从包含该联系人的所有帐户中提取:

    Meteor.users.update({contacts: existingId},{$pull: {contacts: existingId}},{multi: true});