在 meteor mongodb 中删除某些用户时更新所有联系人列表
update all contact lists when some user is deleted in meteor mongdb
我们正在开发联系人列表的简单功能(这是朋友列表的简单版本)。
按照建议 here ,我将 contact_ids 存储在每个用户的联系人中,以便用户 A 可以:
通过
将用户添加到他的联系人
Meteor.users.update(Meteor.userId(), { $push : {contacts: newId});
删除
Meteor.users.update(Meteor.userId(), { $pull : {contacts: existingId });
如果userB决定删除他的账户怎么办?遍历近一百万用户以从联系人中提取 userB id
您可以在一个 mongo 更新中从包含该联系人的所有帐户中提取:
Meteor.users.update({contacts: existingId},{$pull: {contacts: existingId}},{multi: true});
我们正在开发联系人列表的简单功能(这是朋友列表的简单版本)。
按照建议 here ,我将 contact_ids 存储在每个用户的联系人中,以便用户 A 可以:
通过
将用户添加到他的联系人Meteor.users.update(Meteor.userId(), { $push : {contacts: newId});
删除
Meteor.users.update(Meteor.userId(), { $pull : {contacts: existingId });
如果userB决定删除他的账户怎么办?遍历近一百万用户以从联系人中提取 userB id
您可以在一个 mongo 更新中从包含该联系人的所有帐户中提取:
Meteor.users.update({contacts: existingId},{$pull: {contacts: existingId}},{multi: true});